BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tecla1
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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
Jagadishkatam
Amethyst | Level 16

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.';
Thanks,
Jag
unison
Lapis Lazuli | Level 10

Change:

gg= '&giorno.';

to

gg= "&giorno.";

in order for the the macro variable to resolve and be usable in your if-else logic later.

-unison
Tom
Super User Tom
Super User

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;
PaigeMiller
Diamond | Level 26

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
Tecla1
Quartz | Level 8
Many Thanks !!! I know I'm not so good in SAS!!! But I have your help !!!
Have a nice afternoon !!
Tecla

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2699 views
  • 0 likes
  • 5 in conversation