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

Hi all,

is there a way to assosciate numbers from 1 to 12 with the 12 months without having to down the long-winded road of

if x = 1 then my_month = 'JAN';

else if x=2 then my_month = 'FEB';

...

else if x=12 then my_month = 'DEC'

?

Thanks,

Marco

1 ACCEPTED SOLUTION

Accepted Solutions
DBailey
Lapis Lazuli | Level 10

put(mdy(x,1,1960),monname3.)

View solution in original post

6 REPLIES 6
DBailey
Lapis Lazuli | Level 10

put(mdy(x,1,1960),monname3.)

ChrisHemedinger
Community Manager

ooh, just beat me to it.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Lupacante
Calcite | Level 5

Thanks!

but why 1960?

DBailey
Lapis Lazuli | Level 10

the year is actually irrelevant but that's the year for sas date = 0.

ChrisHemedinger
Community Manager

How about:

my_month = put(mdy(x,1,2013),monname3.);

MDY takes a month number, day number, and year.  In your case, the day and year can be anything.

Chris

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
jwillis
Quartz | Level 8

Absolutely.

One way of many is to code a proc format that contains the values.

For example (untested):

proc format;

    value myname

        1 = "JAN"

         2 = "FEB"

etc....

      other = "err"            /* in case you have a number greater than 12, missing or zero */

;

run;

............................

my_month  = put(x,myname.);

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1652 views
  • 0 likes
  • 4 in conversation