BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dg112
Calcite | Level 5
I have a data which has the following date values in numeric type variable,the format is best6.
Date
201304
201406
201409
201412
201311

I want to change it format and want the following result
New_Date
2013/04
2014/06
2014/09
2014/12
2013/11
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way:

data have;
   input Date;
datalines;
201304
201406
201409
201412
201311
;

data want;
   set have;
   new_date = input(put(date,f6.),yymmn6.);
   format new_date yymms7.;
run;

Input works with character values so need to use the Put function to create such and the yymmn informat reads year month values.

Note that the New_date variable will have a presumed day of the month of 1.

View solution in original post

2 REPLIES 2
ballardw
Super User

One way:

data have;
   input Date;
datalines;
201304
201406
201409
201412
201311
;

data want;
   set have;
   new_date = input(put(date,f6.),yymmn6.);
   format new_date yymms7.;
run;

Input works with character values so need to use the Put function to create such and the yymmn informat reads year month values.

Note that the New_date variable will have a presumed day of the month of 1.

Tom
Super User Tom
Super User

In SAS the word FORMAT means the instructions for how to convert the values into text, for example when printing the values in a report.

 

SAS has only two types of variables floating point numbers and fixed length character strings.  Your original values are numbers, like 201,304 or 201,412.  SAS stores DATE values as the number of days since 1960, so over 200 thousand days would be almost 500 years into the future. 

 

So do you want to convert those numbers into character strings? Or date values?

data have;
  input date;
cards;
201304
201406
201409
201412
201311
;

data want;
  set have;
  length new_date $7. date_value 8;
  new_date=put(date,z6.);
  new_date=catx('/',substr(new_date,1,4),substr(new_date,5));
  date_value=input(put(date,z6.),yymmn6.);
  format date_value YYMMS7.;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 852 views
  • 2 likes
  • 3 in conversation