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

I have two fields datesent (Ex: 2022-01-13) is text field with length 32767 and collection_date(Ex:22JAN2022) is number with Date9. format
would like to compare and get line list of records where datesent < collection_date

 

Tried the following to convert datesent but it's not working..

data temp2;
set temp;
format datesent1 date9.;
datesent1 = input ( datesent, date9.);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If datesent is indeed like 2022-01-13 then you want a YYMMDD10. informat not Date9. Input uses the layout of the field, not how you think you want it to look to read the data.

datesent1 = input ( datesent, yymmdd10.);

I am a little concerned about the datesent is 32K characters though. If any of the extra characters come before the date bit then you need to remove them as leading spaces would be significant and might require

datesent1 = input ( strip(datesent), yymmdd10.);

View solution in original post

3 REPLIES 3
ballardw
Super User

If datesent is indeed like 2022-01-13 then you want a YYMMDD10. informat not Date9. Input uses the layout of the field, not how you think you want it to look to read the data.

datesent1 = input ( datesent, yymmdd10.);

I am a little concerned about the datesent is 32K characters though. If any of the extra characters come before the date bit then you need to remove them as leading spaces would be significant and might require

datesent1 = input ( strip(datesent), yymmdd10.);
Cynthia_sas
SAS Super FREQ

Hi:

  With the INPUT function, you need to use an INFORMAT that matches the character string. You want the converted number to use the DATE9. format. But you want your character string to be converted using the yymmdd10. INFORMAT. Otherwise, my guess is that you are seeing error messages in the log like: NOTE: Invalid argument to function INPUT at line xxx column yy.

  Just remember that you are essentially converting the character string from how it looks as a date (yymmdd10.) into a number that is the number of days since Jan 1, 1960. That converted number should be displayed with the DATE9. format. So your FORMAT statement is OK. Your INFORMAT in the INPUT function just needs to be fixed.

Cynthia

 

Stalk
Pyrite | Level 9
Cynthia, You are right about the Note. Followed your suggestion and made the changes. It worked.
Thank you both

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 462 views
  • 0 likes
  • 3 in conversation