I am trying to assign a weekday in a macro variable.I am getting error. Someone please help.
data _null_;
today=date();
day=weekday(today);
call symput('weekday',day);
run;
%put &weekday.;
@Srigyan wrote:
I am trying to assign a weekday in a macro variable.I am getting error. Someone please help.
data _null_; today=date(); day=weekday(today); call symput('weekday',day); run; %put &weekday.;
Your code does NOT cause an ERROR, see the log (Maxim 2):
73 data _null_; 74 today=date(); 75 day=weekday(today); 76 call symput('weekday',day); 77 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 76:23 NOTE: Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit): real time 0.00 seconds cpu time 0.00 seconds 78 79 %put &weekday.; 4
Small correction
data _null_;
day=put(weekday(today()), downame.);
call symput('weekday',day);
run;
%put &weekday.;
Do this instead.
data _null_;
day=put(weekday(today()), downame9.);
call symput('weekday',day);
run;
%put &weekday.;
downame. is a format.
Sorry, my mistake
data _null_;
day=put(weekday(today()+1), downame9.);
call symput('weekday',day);
run;
%put &weekday.;
The WEEKDAY() function is not needed here, and causes the problem.
data _null_;
call symputx('weekday',put(today(),downame.));
run;
%put &=weekday;
Adding
The DOWNAME format expects a valid SAS date, such as '23OCT19'd; but if you take the output of the WEEKDAY function (which is 4, which is how SAS represents Wednesday) and apply the DOWNAME format to it, then it assumes the 4 means that the date in question is January 5, 1960, and that was apparently a Tuesday.
If you want the weekday to be returned then the solution provided by @PeterClemmensen can be further modified to:
data _null_;
day = put(weekday(today()), weekday.);
call symput('weekday',day);
run;
%put &weekday.;
downame is a format that can be used to represent the name of the day based on a date value:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000200842.htm
Similarly, weekday is also a format that writes the day of the week as a number based on a date value:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000200757.htm
Amir.
Hi @Srigyan I think what you need is Weekdate9. format
9 data _null_;
10 today=date();
11 day=put(today,weekdate9.);
12 call symput('weekday',day);
13 run;
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.00 seconds
14
15 %put &weekday.;
Wednesday
@Srigyan wrote:
I am trying to assign a weekday in a macro variable.I am getting error. Someone please help.
data _null_; today=date(); day=weekday(today); call symput('weekday',day); run; %put &weekday.;
Your code does NOT cause an ERROR, see the log (Maxim 2):
73 data _null_; 74 today=date(); 75 day=weekday(today); 76 call symput('weekday',day); 77 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 76:23 NOTE: Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit): real time 0.00 seconds cpu time 0.00 seconds 78 79 %put &weekday.; 4
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.