Desktop productivity for business analysts and programmers

Inverse of the 'month' function

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Inverse of the 'month' function

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


Accepted Solutions
Solution
‎05-09-2014 11:38 AM
Super Contributor
Posts: 578

Re: Inverse of the 'month' function

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

View solution in original post


All Replies
Solution
‎05-09-2014 11:38 AM
Super Contributor
Posts: 578

Re: Inverse of the 'month' function

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

Community Manager
Posts: 2,697

Re: Inverse of the 'month' function

ooh, just beat me to it.

Contributor
Posts: 27

Re: Inverse of the 'month' function

Thanks!

but why 1960?

Super Contributor
Posts: 578

Re: Inverse of the 'month' function

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

Community Manager
Posts: 2,697

Re: Inverse of the 'month' function

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

Regular Contributor
Posts: 217

Re: Inverse of the 'month' function

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

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 325 views
  • 0 likes
  • 4 in conversation