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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.