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

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.;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@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
 

View solution in original post

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

Small correction

 

data _null_;
day=put(weekday(today()), downame.);
call symput('weekday',day);
run;

%put &weekday.;

 

Srigyan
Quartz | Level 8
whats downname here
Srigyan
Quartz | Level 8
Its giving me tuesday, any idea why
PeterClemmensen
Tourmaline | Level 20

Do this instead. 

 

data _null_;
day=put(weekday(today()), downame9.);
call symput('weekday',day);
run;

%put &weekday.;

downame. is a format.

Srigyan
Quartz | Level 8
output is Tuesday, today is wednesday
PeterClemmensen
Tourmaline | Level 20

Sorry, my mistake

 

data _null_;
day=put(weekday(today()+1), downame9.);
call symput('weekday',day);
run;

%put &weekday.;
Srigyan
Quartz | Level 8
Just to know, why _1 is reqired as today() is date for today only
PaigeMiller
Diamond | Level 26

The WEEKDAY() function is not needed here, and causes the problem.

 

data _null_;
call symputx('weekday',put(today(),downame.));
run;

%put &=weekday;

 

--
Paige Miller
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Amir
PROC Star

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.

novinosrin
Tourmaline | Level 20

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
Kurt_Bremser
Super User

@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
 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 4217 views
  • 0 likes
  • 6 in conversation