- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.';
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Change:
gg= '&giorno.';
to
gg= "&giorno.";
in order for the the macro variable to resolve and be usable in your if-else logic later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have a nice afternoon !!
Tecla