BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
billi_billi
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

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;

 

billi_billi
Calcite | Level 5

@Ksharp It worked. Thank you very much. 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1307 views
  • 0 likes
  • 2 in conversation