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.
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.