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

Data is currently stored as date format, YYYYMM. However I would like to create a text column with just year and month. Meaning to say YYMM, I know this is not a good way to store data however I require it in that format. Meaning to say for YYYYMM = 201906, desired output = 1906. YYYYMM = 202006, desired output = 2006. YYYYMM = 200606, desired output = 0606.

data have;
infile datalines missover;
input yymm :yymmn6.;
format yymm yymmn6.;
datalines;
201904
201807
201912
202005
;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you just want to have the existing variable displayed without the century then just change the width of the format.

format yymm yymmn4.;

If instead want to create a character variable then use a PUT() function call.

desired_output = put(yymm,yymmn4.);

View solution in original post

3 REPLIES 3
Ksharp
Super User
data have;
infile datalines missover;
input yymm :yymmn6.;
format yymm yymmn6.;
want=cats(put(yymm,year2.),put(month(yymm),z2.));
datalines;
201904
201807
201912
202005
;
PGStats
Opal | Level 21
data have;
infile datalines missover;
input yymm :yymmn6.;
format yymm yymmn4.;
datalines;
201904
201807
201912
202005
;

proc print; run;

image.png

PG
Tom
Super User Tom
Super User

If you just want to have the existing variable displayed without the century then just change the width of the format.

format yymm yymmn4.;

If instead want to create a character variable then use a PUT() function call.

desired_output = put(yymm,yymmn4.);

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
  • 978 views
  • 1 like
  • 4 in conversation