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
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;
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.
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.
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;
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.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.