data TEST; set DATASET; monthIn = scan(Date,1); month = input(monthIn,4.); day = input(scan(Date,2),4.); year = input(scan(Date,3),4.); run;
I have dates like Date=9/1/2012
and my code returns monthIn=9 month=. day=1 year=2012.
Why does month not return month=9?
Try this.
data TEST;
input date $;
monthIn = scan(Date,1);
month = input(monthIn,4.);
day = input(scan(Date,2),4.);
year = input(scan(Date,3),4.);
datalines;
9/1/2012
;
run;
proc print data=test;
run;
It's normally better to convert a string representing a date into an actual SAS date value. Once you've got a SAS date value you can format however you want to with either OOTB formats or your own picture format.
proc format;
picture mdy_nums
low-high ='month=%m Day=%d Year=%Y' (datatype=date)
;
quit;
data TEST;
input date $;
sas_date=input(date,mmddyy10.);
format sas_date mdy_nums.;
month=month(sas_date);
day=day(sas_date);
year=year(sas_date);
datalines;
9/1/2012
;
run;
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.