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'


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 955 views
  • 4 likes
  • 4 in conversation