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.);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 469 views
  • 1 like
  • 4 in conversation