Hi everyone, I am trying to convert a date variable that is stored as a character variable into a numeric variable. However, the date variable is in the format "02 AUG 2017". I want the result outputted as a new date variable that is numeric.
data want;
set have;
date=input(character_date,date10.);
format date date10.;
run;
Nothing that I have tried has worked. I would appreciate any assistance. Thank you in advance.
Count the number of characters in your string, including the blanks, and you will see that you need to read 11 characters.
Therefore this works:
data want;
character_date = '02 aug 2017';
date=input(character_date,date11.);
format date date9.;
run;
Count the number of characters in your string, including the blanks, and you will see that you need to read 11 characters.
Therefore this works:
data want;
character_date = '02 aug 2017';
date=input(character_date,date11.);
format date date9.;
run;
And if your data is a bit sloppy about consistent lengths you may want a different informat with more flexibility.
data want; character_date = '02 aug 2017'; date=input(character_date,anydtdte.); format date date9.; run;
The Anydtdte format by default allows more characters and will read some fairly messy dates but caution is needed if you have two-digit years at the start of your date.
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.