I have character dates and converting them to num date9. but fails to work for char date which is like "2 FEB 2021".
char_date
22 DEC 2020
2 FEB 2021
i use the below step and it works for first record but doesnt work for second one.
ADT=input(char_date, date9.);
How do i get 0 in case day is single digit.
Any clue please
To get a leading zero, either use a custom format for DATE9, or use another standard format:
data have;
input char_date $20.;
datalines;
22 DEC 2020
2 FEB 2021
;
proc format;
picture mydate
other='%0d%b%Y' (datatype=date language=english)
;
run;
data want;
set have;
num_date = input(compress(char_date),date9.);
format num_date mydate9.;
run;
or
data want;
set have;
num_date = input(compress(char_date),date9.);
format num_date yymmdd10.;
run;
For example, if you do this and remove the spaces, it will be recognized.
ADT=input(compress(char_date), date9.);
No, unfortunately it didnt work
can you provide data that can be reproduced using datalines in the data step?
To get a leading zero, either use a custom format for DATE9, or use another standard format:
data have;
input char_date $20.;
datalines;
22 DEC 2020
2 FEB 2021
;
proc format;
picture mydate
other='%0d%b%Y' (datatype=date language=english)
;
run;
data want;
set have;
num_date = input(compress(char_date),date9.);
format num_date mydate9.;
run;
or
data want;
set have;
num_date = input(compress(char_date),date9.);
format num_date yymmdd10.;
run;
data want; set have; num_date = input(char_date,date11.); format num_date date9.; run;
Tell the INPUT() function to use the full length of the string instead of truncating at 9 characters.
data have;
input char_date $11.;
cards;
22 DEC 2020
2 FEB 2021
;
data want;
set have;
date = input(char_date,date11.);
format date date9. ;
run;
Obs char_date date 1 22 DEC 2020 22DEC2020 2 2 FEB 2021 02FEB2021
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.