Have several programs that have the same date variable changing each quarter..
Wrote the code at the start of the program to change the one date variable each quarter - code runs once a quarter.
data null; %global qstart ; %global qtr_numb; qstart = intnx('quarter',date(),-0); */first day of quarter. qtr_numb =compress("QTR" || qtr(intnx('quarter',date(),-0))); */ this quarter format qstart date9.; put qstart; put qtr_numb; run;
01JUL2025 */correct result. QTR3 */correct result
All good. First variable is date, second variable is a concatenation of the string "QTR" and the numeric value of the quarter. No thought at all went into the design of the data sets, instead of one variable with the results for eacg quarter, they of course, made four distinct variables = QTR1, QTR2, QTR3, QTR4. That's not too bad, but there are data sets with 40 variables, 20 of them are one variable repeated 20 times. Data sets are unnaturally long.
data BASE (keep = GROUP accountID &QTR_numb. );
set based;
Run;
When I place the variable &qtr_numb in a KEEP statement as above I get the following error:
compress("QTR" || qtr(intnx('quarter',date(),-0))) ERROR 214-322: Variable name ( is not valid.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, /, ;, _DATA_, _LAST_, _NULL_.
ERROR 23-7: Invalid value for the KEEP option.
ERROR 200-322: The symbol is not recognized and will be ignored.
----- --------- - 23 23 22 ERROR 22-7: Invalid option name ,.
1 ! compress("QTR" || qtr(intnx('quarter',date(),-0))) ----- 214 ERROR 214-322: Variable name "QTR" is not valid.
Why is SAS interpreting the variable assignment as a literal string?
The first variable above - an actual day, DID originally work in a simple data step like below, but no longer works:
data SAMP ; set VAMP; where sampdate ge &Qstart. ; run;
LOG:
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. ERROR 76-322: Syntax error, statement will be ignored. ERROR: Syntax error while parsing WHERE clause. 43 where sampdate ge &Qstart. ; - 22 76
Are there supposed to be double ampersands, triple? I will need to use one or more of the two variables in
Where clause in data steps.
Keep/Drop statements
PROC SQL.
Thanks.
... View more