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

Hi All,

 

I'm relatively new to SAS programming having had experience with MSSQL, MySQL mostly.

 

I am trying to get the month as a string from a date in the format 'mm'.

For example: 01JAN2017 would result in '01'. 01FEB2017 would result in '02' etc.

I need the preceding 0 for months 1-9

 

I have been looking at PUT function(?) to do this but cannot find a format that is going to do what I need it to do.

 

Anyone have any solution or ideas to point me in the right direction?

1 ACCEPTED SOLUTION

Accepted Solutions
RahulG
Barite | Level 11

Try this

 

data _null_;

dt='01Jan17'd;
mon_val=put(month(dt),z2.);
put mon_val=;
run;

View solution in original post

2 REPLIES 2
RahulG
Barite | Level 11

Try this

 

data _null_;

dt='01Jan17'd;
mon_val=put(month(dt),z2.);
put mon_val=;
run;
bradja
Fluorite | Level 6
You my friend, are a legend.
This appears to do exactly what I need!

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
  • 2 replies
  • 751 views
  • 1 like
  • 2 in conversation