Programming the statistical procedures from SAS

Reading DOB data

Reply
Super Contributor
Posts: 276

Reading DOB data

I have DOB values, some of which look like this:   9/23/1996  12:00:00 AM  

Others are like this:  3/1/1998  12:00:00 AM

 

Using the length statement dob $10 works for the first one but not the 2nd. Instead, I get 3/1/1998 1

 

What I want is just the date:

9/23/1996

3/1/1998

Super User
Posts: 10,871

Re: Reading DOB data

You don't say if you want the time as well but to read the date I would start with an informat of ANYDTDTE. and then assign the mmddyy10. format for use. This way you will have an actual date that can be manipulated with many functions instead of a not very nice character value.
Super Contributor
Posts: 276

Re: Reading DOB data

i want just the date.
Super User
Posts: 18,580

Re: Reading DOB data

Try anydtDTM for a date time variable. Then use the Datepart function to get only the date specific portion.
Super Contributor
Posts: 276

Re: Reading DOB data

I think I may have to forget the data step I'm using. The files I'm reading have changed from last year.  Right now I have:

data student;

length dob $10 .................;

infile '.........';

input dob $;

new_dob=input(dob,yymmdd10.);

run;

Super User
Posts: 10,871

Re: Reading DOB data

Try:

data student;
infile '.........';
informat dob AnyDtDTE. ;
input dob ;
Format dob mmddyy10. ;
run;

and see if that work. I have a number of files where the data source appends a spurious "time" that I ignore by reading just the date part using similar code.

 

Super User
Posts: 5,255

Re: Reading DOB data

The program that you have is a good match for the data you have shown.  You would run into a problem if your program were different.  for example:

 

input dob $10.;

 

That would read in the extra character that you are seeing.  But this would be fine:

 

length dob $ 10;

input dob $;

 

Another place you could go wrong is by adding an informat:

 

informat dob $10.;

 

But what you have posted is a good match and should be working.

Valued Guide
Posts: 632

Re: Reading DOB data

data have;
infile datalines truncover;
input cdate $30.;
datalines;
 9/23/1996  12:00:00 AM  
3/1/1998  12:00:00 AM
run;

data want;
set have;
date = input(scan(cdate,1,' '),anydtdte.);
format date date9.;
run;

Ask a Question
Discussion stats
  • 7 replies
  • 366 views
  • 0 likes
  • 5 in conversation