@Emoji wrote:
Variable Market is a variable (string) from Work.my_old_table. By using Market = XXX, I was trying to say that the when String market is XXX (in reality it is something like 'market_data', the rest of the code should be executed.
I ran the code that you shared and got the following error:
49 date = intnx('qtr','01jan2022'd,qtr-1,'b') to intnx('qtr','01jan2022'd,qtr-1,'e');
__
22
2 The SAS System 06:13 Tuesday, December 13, 2022202
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,
IN, LE, LT, MAX, MIN, NE, NG, NL, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.ERROR 202-322: The option or parameter is not recognized and will be ignored.
To test a variable's value you need to use SAS code, not MACRO code.
There is no way that the code I posted would produce that message.
It looks like you removed the DO keyword from the DO loop.
The syntax for an iterative DO loop is
do <varname> = <initial value> [to <final_value>] [ by <increment> ] ;
You don't state what this code is supposed to be doing, and it is always helpful to state what the code is supposed to be doing.
It looks like you are trying to compute the number of days in a quarter by using a loop, and it was already explained in your earlier thread that loops are not needed to do this.
So that's my guess anyway. Regardless, tell us the purpose of this code, tell us what it is supposed to be doing. Whatever the purpose, you have adopted a very difficult approach to get this done, and if we only knew what you were doing, I'm sure many people could suggest simpler and faster ways to do what you want.
I like @Patrick's second solution.
data my_new_table;
set my_old_table;
format date date9.;
if market = "xxxx" then do date = '01jan2022'd to '31dec2022'd;
qtr=qtr(date);
output;
end;
run;
You say you want to calculate the number of days in each quarter but don't show how it's used.
If after all this you still do not have a solution that works, I would suggest taking a step back as this is definitely an xy problem.
Rather than posting your non working code, please show us a small sample of your input data and what you want as output instead.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.