Hello
I am trying to convert a character variable that represents a date into a numeric SAS date variable, but my character variable has dates with single and double digit day (for example 3 Jun 2020 and 03 Jun 2020). Below is my code, when I use date9. informat, the dates with double digit day were converted but not dates with single digit day. Then I tried anydtdte. , then single digit day dates were converted but not other ones and in the log note showed up:
NOTE: Invalid argument to function INPUT at line xx column xx.
Is there any way to handle both single and double-digit days date?
data sd;
set raw.sd;
format SDADAT_date yymmdd10.;
SDADAT_date = input(strip(SDADAT_RAW),?? date9.);
/*SDADAT_date = input(strip(SDADAT_RAW),anydtdte.);*/
run;
Try informate DATE11. :
data have;
SDADAT_RAW='3 Jun 2020 ';SDADAT_date = input(strip(SDADAT_RAW),?? date11.);
output;
SDADAT_RAW='03 Jun 2020';SDADAT_date = input(strip(SDADAT_RAW),?? date11.);
output;
format SDADAT_date date9.;
run;
Try informate DATE11. :
data have;
SDADAT_RAW='3 Jun 2020 ';SDADAT_date = input(strip(SDADAT_RAW),?? date11.);
output;
SDADAT_RAW='03 Jun 2020';SDADAT_date = input(strip(SDADAT_RAW),?? date11.);
output;
format SDADAT_date date9.;
run;
@Ksharp It worked. Thank you very much.
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.