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

I have a dataset which has a column named Month in yymmdd10. format. 

How can I use the information in the Month column to create a new column called

Month2 whereby the data is in the following format - 200901, 200902, ...200912:

for e.g. 

200901 for 2009-01-01

201212 for 2012-01-01

..etc

I would like Month2 to be just numbers. 

Thanks in advance!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
New_col=input(put(date,yymmn6. -l),6.);

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Don't create a new column. Just assign the YYMMN6. format to this variable.

--
Paige Miller
ubshams
Quartz | Level 8

Thanks but I actually need the new column to be in a numbers format to match with 

our internal database. So they need to be in the 200901, 200902, etc format.

novinosrin
Tourmaline | Level 20
New_col=input(put(date,yymmn6. -l),6.);
PaigeMiller
Diamond | Level 26

@ubshams wrote:

Thanks but I actually need the new column to be in a numbers format to match with 

our internal database. So they need to be in the 200901, 200902, etc format.


Actually, no you don't. When you need numbers to be 200901, 200902, etc, you use the YYMMN6. format. When you want them to be 2009-01-01 you use the YYMMDD10. format. And so on. This leaves the value as a true SAS date value.

 

The solution you marked correct does not result in SAS date values, it results in integers where you have to provide the logic  to find what month comes before 201001 and how many months are in between 200908 and 201006, and so on. Many drawbacks.

--
Paige Miller
mklangley
Lapis Lazuli | Level 10

@ubshams  Like this?

data have;
    input month :yymmdd10.;
    format month yymmdd10.;
    datalines;
    2009-01-01
    2012-01-01
    2020-10-06
    ;
run;

data want;
    set have;
    month2 = input(put(month, yymmn6.), 6.);
run;
Reeza
Super User
month_number = year(date)*100 + month(date);

@ubshams wrote:

I have a dataset which has a column named Month in yymmdd10. format. 

How can I use the information in the Month column to create a new column called

Month2 whereby the data is in the following format - 200901, 200902, ...200912:

for e.g. 

200901 for 2009-01-01

201212 for 2012-01-01

..etc

I would like Month2 to be just numbers. 

Thanks in advance!

 

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 668 views
  • 0 likes
  • 5 in conversation