Good afternoon,
I need to put contidions in a call symput to avoid problems due to 'saturday' and 'sunday'.
I try with this but it's not quiet correct:
data _null_ ;
call symput('giorno',compress(put(today()-0 , DOWNAME. ))) ;
run;
%put 'giorno =' &giorno.;
data _null_;
gg= '&giorno.';
if gg eq 'Monday' then call symput('data_estrazione_3',compress(put(today()-3 ,date9.)));
else
call symput('data_estrazione_3',compress(put(today()-1 ,date9.)));
run;
%put data_estrazione_3= &data_estrazione.;
Please, can you help me?
Thanks, Tecla
There's really no need to create macro variable &giorno in this situation. The WEEKDAY() function eliminates the need for &giorno. That would also simplify the code.
data _null_;
if weekday(today())=2 then date=today()-3;
else date=today()-1;
call symputx('data_estrazione_3',put(date,date9.));
run;
%put &=data_estrazione_3;
The obvious error to me is in this line:
%put data_estrazione_3= &data_estrazione.;
You don't have a macro variable named &data_estrazione so you get the error message.
Another issue with the code is when we call the macro variable please call in double quotes and not single quote. In the code the macro variable is called in single quote due to which it will not resolve. Try calling the macro variable with double quotes.
gg= '&giorno.';
Change:
gg= '&giorno.';
to
gg= "&giorno.";
in order for the the macro variable to resolve and be usable in your if-else logic later.
The main issue is that macro triggers are not evaluated inside strings that are quoted by single quote characters instead of double quote characters. So you are comparing Monday to &giorno instead of the value of the GIORNO.
Also you can simply by using the newer (10+ years old?) CALL SYMPUTX() instead of the older CALL SYMPUT().
data _null_ ;
call symputx('giorno',put(today(),DOWNAME.));
run;
data _null_;
date=today()-1;
if "&girono" eq 'Monday' then date=date-2;
call symputx('data_estrazione_3',put(date,date9.));
run;
There's really no need to create macro variable &giorno in this situation. The WEEKDAY() function eliminates the need for &giorno. That would also simplify the code.
data _null_;
if weekday(today())=2 then date=today()-3;
else date=today()-1;
call symputx('data_estrazione_3',put(date,date9.));
run;
%put &=data_estrazione_3;
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.