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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

13 REPLIES 13
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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 ;
DeclanBall
Fluorite | Level 6
Ok thanks, that I didn't know.

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?
RW9
Diamond | Level 26 RW9
Diamond | Level 26

So:

data want;
  have=1706;
  want=input(cats(put(have,4.),"01"),yymmdd6.);
  format want monname3.;
run;
ballardw
Super User

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;
DeclanBall
Fluorite | Level 6
Due to not having CAT function (base SAS), this has saved my day. Many thanks everyone for your help
Reeza
Super User

CATT is in Base SAS....for a long time.

DeclanBall
Fluorite | Level 6
I must not have even base SAS then, log reports that function cannot be accessed 😞
Reeza
Super User

@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?

DeclanBall
Fluorite | Level 6

Unsure of what version of SAS I am using, however this is my log:

 

error.PNG

Reeza
Super User

What do you get for this:

 

%put &sysvlong;

DeclanBall
Fluorite | Level 6
8.02.02MOP020601
Reeza
Super User

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 😉 

 

https://blogs.sas.com/content/iml/2013/08/02/how-old-is-your-version-of-sas-release-dates-for-sas-so...

Reeza
Super User

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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