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'


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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