BookmarkSubscribeRSS Feed
Kels123
Quartz | Level 8

Through a data request, I am working with a database of dates and corresponding measurements. In order to use the dates, I want to make sure they are all in the same format and readable/usable as dates but I am running into some unexpected issues.

 

The date variables are called insurance_dt1 through insurance_dt26. Through proc contents, I can see that all the date variables are numeric with a length of 8., but only 1-15 have an associated date format (YYMMDD10.) whereas 16-26 have no date formatting. Looking closer, I can see why-- some of the date variables were provided to me in a different format that I do not immediately recognize. For example:

 

insurance_dt14   insurance_dt15   insurance_dt16   insurance_dt17   insurance_dt18   insurance_dt19

2013-05-21         2013-06-05        19740                  20355                  19358                 19390

 

I have tried converting them into YYMMDD10. format using the following codes within a datastep, but they usually just turn into missing values or the date 1960-01-02 or 1960-01-03 :

 

new_ins_dt16=input(ins_dt16,yymmdd10.);

    format new_ins_dt16 yymmdd10.;

 

new_ins_dt16 = INPUT(ins_dt16,8.);

    FORMAT new_ins_dt16 YYMMDD10.;

 

new_ins_dt16 = INPUT(PUT(ins_dt16,8.),YYMMDD8.);

    FORMAT new_ins_dt16 YYMMDD10.;

 

I am wondering if I am not properly recognizing the format and thus somehow causing SAS to be unable to read in the dates properly. Alternatively, these dates could be partially incomplete (e.g. missing the exact day), but that does not seem right either since these days visually appear to be more like unformatted SAS dates as opposed to incomplete days. I am not sure, for example, how to interpret something like "20355". Any suggestions would be very much appreciated. Thank you.

1 REPLY 1
art297
Opal | Level 21

They are already SAS dates and are only missing the formats. e.g.:

data have;
  informat insurance_dt14-insurance_dt15 yymmdd10.;
  format insurance_dt14-insurance_dt19 yymmdd10.;
  input insurance_dt14-insurance_dt19;
  cards;
2013-05-21         2013-06-05        19740                  20355                  19358                 19390
;

Art, CEO, AnalystFinder.com

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 843 views
  • 0 likes
  • 2 in conversation