Hello All!
I need some help. I'm trying to have SAS read Nonstandard data from a comma-delimited raw data file, and no matter what I do it will not process the date correctly. The issue is with the BirthDate data, the raw file has them formatted DD/MM/YYYY. I specified on the input statement to have BirthDate:ddmmyy10. but SAS is processing all the date outputs as JAN1960 or DEC1959. For example, one of the raw birth dates is 16/10/1986 but SAS is displaying it as JAN1960. Below is my code, partial output, and the raw data. Can anyone see what I am doing wrong?
Here is my code:
data work.customers;
infile "/folders/myfolders/Data1/custca.csv"
dlm=',';
input First :$20. Last :$20. ID
Gender :$1. BirthDate:ddmmyy10. Age AgeGroup :$12.;
drop ID Age;
format BirthDate DTMONYY7.;
label BirthDate='Birth*Date';
run;
proc print data=work.customers label;
run;
proc contents data=work.customers varnum;
run;
Here is a partial output:
Customers
| 1 | Bill | XXXXX | M | JAN1960 | 15-30 years |
|---|---|---|---|---|---|
| 2 | Susan | XXXXX | F | DEC1959 | 46-60 years |
| 3 | Andreas | XXXXX | M | DEC1959 | 61-75 years |
Variables in Creation Order
Format Informat Label
| 1 | First | Char | 20 | |||
|---|---|---|---|---|---|---|
| 2 | Last | Char | 20 | |||
| 3 | Gender | Char | 1 | |||
| 4 | BirthDate | Num | 8 | DTMONYY7. | DDMMYY10. | Birth*Date |
| 5 | AgeGroup | Char | 12 |
Here is the raw data file edited with X's for this thread: (it is a csv file)
Bill,XXXXX,IDXXXX,M,16/10/1986,21,15-30 years
Susan,XXXXX,IDXXXX,F,09/07/1959,48,46-60 years
Andreas,XXXXX,IDXXXX,M,18/07/1934,73,61-75 years
Lauren,XXXXX,IDXXXX,F,24/10/1986,21,15-30 years
Lauren,XXXXX,IDXXXX,F,18/08/1969,38,31-45 years
Tommy,XXXXX,IDXXXX,M,20/01/1959,48,46-60 years
Colin,XXXXX,IDXXXX,M,20/01/1934,73,61-75 years
Lera,XXXXX,IDXXXX,F,11/07/1986,21,15-30 years
Wilma,XXXXX,IDXXXX,F,23/06/1984,23,15-30 years
Patrick,XXXXX,IDXXXX,M,14/04/1939,68,61-75 years
Portia,XXXXX,IDXXXX,F,11/02/1964,43,31-45 years
Soberina,XXXXX,IDXXXX,F,27/09/1986,21,15-30 years
Angel,XXXXX,IDXXXX,F,19/12/1969,38,31-45 years
Alex,XXXXX,IDXXXX,M,22/04/1986,21,15-30 years
Kenan,XXXXX,IDXXXX,M,10/02/1964,43,31-45 years
Informat is how the data will be read IN, format is how the data will be displayed. You should use both.
informat birthdate ddmmyy10.;
format birthdate ddmmyy10.;
Informat is how the data will be read IN, format is how the data will be displayed. You should use both.
informat birthdate ddmmyy10.;
format birthdate ddmmyy10.;
Hey Marc!
Alright, so I tried that and it now recognizes the dates correctly!!
Thank you so much!!!
Change the informat and format for whatever situation applies.
informat birthdate ddmmyy10.;
format dtmonyy7.;
should do the trick.
Mark
Thank you all!!
Remove that DT from dtmonyy
It is suitable when the value is a timestamp but you have a date
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.