Hello,
I have dates being generated in a numeric format of yymm (eg. 1706 = June2017).
I have been trying to substring it to grab the month and then convert it into "mmm" using monname3. but with no success. In the example above I am trying to grab "Jun".
As a test I have tried:
data test ;
mon=06 ;
month=put(mon,monname3.) ;
run ;
However this always returns "Jan" in month?! Very confused, any help is much appreciated.
Declan
Ugly but is this what you want:
data junk; date = 1706; mon = put(mdy(input(substr( put(date,4.) ,3),2.),1,2000),monname3.); run;
Dates, regardless of how you format them, are stored as number of days since a certain timepoint. Thus they always need to contain the three parts Year, month, and day, and from that the number of days can be derived. With this number of days you can then apply formats to display that data differently. Now when you say display 6 as a date format, it assumes the 6 means 6 days and converts that to be 6 days from the default timepoint, so always going to be Jan in this instance as 01JAN1966 (or whatever it is, can't think off top of my head) is 07Jan1966, displayed as month is Jan. What you want is a date:
data test ; mon='01jan2017'd ; month=put(mon,monname3.) ; run ;
So:
data want; have=1706; want=input(cats(put(have,4.),"01"),yymmdd6.); format want monname3.; run;
Ugly but is this what you want:
data junk; date = 1706; mon = put(mdy(input(substr( put(date,4.) ,3),2.),1,2000),monname3.); run;
CATT is in Base SAS....for a long time.
@DeclanBall wrote:
I must not have even base SAS then, log reports that function cannot be accessed 😞
You couldn't use the previous answer either if you don't have BASE SAS. What are you using?
Unsure of what version of SAS I am using, however this is my log:
What do you get for this:
%put &sysvlong;
SAS 8 was released in 1999 so that's 18 years old.....so you have an Ancient* version of SAS.
18 year olds are pretty unruly these days.
PS. That's the technical term 😉
Convert it to a SAS date using INPUT and PUT.
data have;
x= 1706;
y = put(x, 8. -l);
z = input(catt('20', y), yymmn6.);
monName = put(z, monname3.);
format z date9.;
run;
proc print data=have;run;
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.
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.