BookmarkSubscribeRSS Feed
david27
Quartz | Level 8

I have this:

 

%let yyyymm=202109;
data temp;
format yearmonth monyy7.;
yearmonth=&yyyymm.;
run;

The resulting yearmonth variable has value "MAY2513"

 

 

Want:

It should be 'SEP2021'

3 REPLIES 3
Tom
Super User Tom
Super User

If you want the variable YEARMONTH to work with a date type format, such as MONYY, then it has to have date values, not random numbers like 202,109.

 

yearmonth=input("&yyyymm.01",yymmdd8.);

 

AMSAS
SAS Super FREQ

@david27 
In SAS 202,109 is a number it is not a date. SAS stores dates as the number of days since 01/01/1960 (day 0), so 202109 is a day in May 2513.
What you need to do is convert 2021-09 into a SAS date value
There's a number of ways to do this, probably the simplest is the MDY function
Please review the documentation links and feel free to ask any additional questions

Reeza
Super User
%let yyyymm=202109;

data temp;
format yearmonth monyy7.;
yearmonth=input("&yyyymm.", yymmn6.);
run;

proc print;run;

@david27 wrote:

I have this:

 

%let yyyymm=202109;
data temp;
format yearmonth monyy7.;
yearmonth=&yyyymm.;
run;

The resulting yearmonth variable has value "MAY2513"

 

 

Want:

It should be 'SEP2021'


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 548 views
  • 4 likes
  • 4 in conversation