DATA Step, Macro, Functions and more

How to read date in this format

Reply
Occasional Contributor
Posts: 12

How to read date in this format

Hi Everyone,

 

I'm have a text file with date of birth entered in the format of mm/yyyy in numbers. So for example 5/1985.

 

When I try to tell sas to read the data with informat - DOB monyy6. it says invalid data for DOB. I'm guessing that it's because it's not a 3 letter representation of a month.

 

What would be the other informat because I tried mmyy6. and that doesn't exist.

 

Here's my code:

 

data temp;
	infile 'C:\Users\wjeon\Desktop\Masters\Data to William\PEI data/PEItxt.txt' delimiter='09'x dsd missover firstobs=2;
	length Patient_ID $20;
	informat Patient_ID $20. Gender 1. DOB mmyy10. Postal_Code $3. Region 1. Date_of_Service mmddyy10. Facility_type_id 2. ICD_9 $4. Specialty 3. Paid_amt best32. Approved_amt best32. Fee_Code $4.;
	input Patient_ID Gender DOB Postal_Code Region Date_of_Service Facility_type_id ICD_9 Specialty Paid_amt Approved_amt Fee_Code;
run;

I also tried to make it read it as characters so that i can try to convert it later on but it still says invalid

 

Thank you in advance.

Super Contributor
Posts: 490

Re: How to read date in this format

[ Edited ]
data test;
input DOB $ ;
dt = input('01/'!!DOB,ddmmyy10.);
format dt mmyys. ;
datalines;
3/2011
;
run;
Super User
Posts: 19,780

Re: How to read date in this format

Use the ANYDTDTE. informat.

 

data want;
informat dob anydtdte.;
format dob date9.;
input dob;
cards;
1/2016
5/2011
12/2010
;
run;
Valued Guide
Posts: 2,177

Re: How to read date in this format

Let SAS do the informat searching for you!
See the paper on the idea
VFORMAT Lets SAS® Do the Format Searching
http://support.sas.com/resources/papers/proceedings14/1744-2014.pdf
Ask a Question
Discussion stats
  • 3 replies
  • 236 views
  • 2 likes
  • 4 in conversation