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!
New_col=input(put(date,yymmn6. -l),6.);
Don't create a new column. Just assign the YYMMN6. format to this variable.
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.
New_col=input(put(date,yymmn6. -l),6.);
@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.
@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;
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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.