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!

 

 


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 6 replies
  • 940 views
  • 0 likes
  • 5 in conversation