BookmarkSubscribeRSS Feed
GreggB
Pyrite | Level 9

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

7 REPLIES 7
ballardw
Super User
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.
GreggB
Pyrite | Level 9
i want just the date.
Reeza
Super User
Try anydtDTM for a date time variable. Then use the Datepart function to get only the date specific portion.
GreggB
Pyrite | Level 9

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;

ballardw
Super User

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.

 

Astounding
PROC Star

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.

ArtC
Rhodochrosite | Level 12

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;

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!

What is ANOVA?

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.

Discussion stats
  • 7 replies
  • 1621 views
  • 0 likes
  • 5 in conversation