DATA Step, Macro, Functions and more

Weekday text to value

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Weekday text to value

Is there a function in SAS to that converts "Sunday" = 1, "Monday" = 2, etc. or should I just write the codes to do it?

 


Accepted Solutions
Solution
‎06-30-2016 10:59 AM
Super User
Posts: 17,836

Re: Weekday text to value

I think you need to write the code Smiley Sad 

 

Typically you can browse by category for reference. 

https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p0w6napahk...

View solution in original post


All Replies
Contributor
Posts: 25

Re: Weekday text to value

[ Edited ]

Check out the WEEKDAY function which returns a number (1 to 7, I think) based on a SAS date. For example,

day_no = WEEKDAY( SASdate ); 

 

New Contributor
Posts: 4

Re: Weekday text to value

I believe this returns weekday based on SAS date value which is numeric. 

I was wondering if there's any function that converts actual text i.e. "Sunday" into 1.

Contributor
Posts: 25

Re: Weekday text to value

The WEEKDAY function does use a SAS date. I assumed that you had the date availabel as a SAS date. If it is just a matter of mapping a string to a value, that's a job for PROC FORMAT.

 

proc format;
  value $day2num
  'Sunday' = '1'
  'Monday' = '2'
  ...
  ;
  run;

data x;
  daynum = put( daystring, $day2num. );  
Solution
‎06-30-2016 10:59 AM
Super User
Posts: 17,836

Re: Weekday text to value

I think you need to write the code Smiley Sad 

 

Typically you can browse by category for reference. 

https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p0w6napahk...

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 294 views
  • 2 likes
  • 3 in conversation