BookmarkSubscribeRSS Feed
pchappus
Obsidian | Level 7

Is the only way to read in a date that comes through with varying lengths for the month is to read it in as a string first and then change it to a date once it is read in?

 

Thanks,

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Can you post an example of what your values are to avoid assumptions

 

 


@pchappus wrote:

Is the only way to read in a date that comes through with varying lengths for the month is to read it in as a string first and then change it to a date once it is read in?

 

Thanks,


 

PeterClemmensen
Tourmaline | Level 20

Post an example please

Reeza
Super User

@pchappus wrote:

Is the only way to read in a date that comes through with varying lengths for the month is to read it in as a string first and then change it to a date once it is read in?

 

Thanks,


Nope.

ballardw
Super User

I read a fair amount of data from CSV files with a data step that usually contains one or more date variables. Unless by "varying lengths for the month" you mean Jan Janu etc then the mmddyy10. informat handles most variations nicely except for a 6 digit without / delimiters.

data example;
   informat date mmddyy10.;
   input date;
   format date date9.;
datalines;
01/01/2019
1/1/2019
01/1/2019
1/01/2019
01012019
1012019
112019
;
run;

All except the last value will return 01JAN2019. The last assumes the year is only 2 digits because that 6 digit is subject to way to many interpretations.

 

pchappus
Obsidian | Level 7

I actually ended up getting it to work. I used MMDDYY8. and it seemed to realized if the month was a Jan-Sept and added the leading zero. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 762 views
  • 0 likes
  • 5 in conversation