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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I think you need to write the code 😞 

 

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

4 REPLIES 4
sh0e
Obsidian | Level 7

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

 

kimih0223
Fluorite | Level 6

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.

sh0e
Obsidian | Level 7

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. );  
Reeza
Super User

I think you need to write the code 😞 

 

Typically you can browse by category for reference. 

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 2139 views
  • 2 likes
  • 3 in conversation