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. 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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