- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
My issue is that my dates are being given to me in the numeric YYMM format, I have no control over that. How do I get from that to a position where I can extract MM as "Jun" etc?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So:
data want; have=1706; want=input(cats(put(have,4.),"01"),yymmdd6.); format want monname3.; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
CATT is in Base SAS....for a long time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Unsure of what version of SAS I am using, however this is my log:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you get for this:
%put &sysvlong;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;