I have a data set, the month variable:month is CHAR7. So there is only year and month, ,shown as this format
2015-11
2015-12
I need to change them into NOV2015, DEC2015. So firstly i need change it into SAS .
I tried:
date=input(month, date7.) or other time formate, but it doesnt work.
As i need use conditional statement, so i dont want to separate them into year and month into to column, i hope they still stay in the same column.
28 data want;
29 Date_Char = '2015-11';
30 Date_Num = input(strip(Date_Char) !! '-01', yymmdd10.);
31 format Date_Num date9.;
32 put _all_;
33 run;
Date_Char=2015-11 Date_Num=01NOV2015 _ERROR_=0 _N_=1
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
NOTE: Compressing data set WORK.WANT increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
28 data want;
29 Date_Char = '2015-11';
30 Date_Num = input(strip(Date_Char) !! '-01', yymmdd10.);
31 format Date_Num date9.;
32 put _all_;
33 run;
Date_Char=2015-11 Date_Num=01NOV2015 _ERROR_=0 _N_=1
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
NOTE: Compressing data set WORK.WANT increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
it works. i added a format, so it output as NOV2015. thanks.
data test1;
set aa (keep=month);
date=input(strip(month)!!'-1', yymmdd10.);
format date monyy7.;
run;
Note that SAS has new functions for concatenating strings. even newer than the relatively new STRIP() function.
Date_Num = input(cats(Date_Char,'-01'), yymmdd10.);
yes, it works, i also tried. thank you~
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: