Help using Base SAS procedures

I NEED URGENT HELP With Date Format!

Reply
Occasional Contributor
Posts: 11

I NEED URGENT HELP With Date Format!

Hi,

I've got together some SAS codes to convert TWO separate related datasets in .txt format into ONE SAS data set. The two data sets are for hospital discharges in 1994-1999 and 2000-2004 respectively.

The data for the 3 dates (birth, admission and discharge) are arranged in the .txt data as follows:

1. admission date (doa): in the columns 18 to 23; altogether 6 characters.

2. discharge date (dod): in the columns 27 to 32; altogether 6 characters. and

3. birth date (dob): in the columns 37 to 42; altogether 6 characters.

I used the following SAS code to read the .txt data into SAS data. But I keep generating error messages for the dates:

filename hys ('e:\hys_1995_1999.txt' , 'e:\hys_2000_2004.txt') lrecl=450;
data a;
infile hys;
informat doa dod dob mmddyy6.;
format doa dod dob mmddyy8.;
input
@018 doa
@027 dod
@037 dob
;
run;

Can anyone help me please identify and correct for me the error in the above?

Thanks!

Jeremy.
Contributor
Posts: 33

Re: I NEED URGENT HELP With Date Format!

What is the error message you get?
Occasional Contributor
Posts: 11

Re: I NEED URGENT HELP With Date Format!

12 filename hys ('e:\hys_1995_1999.txt' , 'e:\hys_2000_2004.txt') lrecl=450;
13 data a;
14 infile hys;
15 informat doa dod dob mmddyy6.;
16 format doa dod dob mmddyy8.;
17 input
18 @018 doa
19 @027 dod
20 @037 dob
21 ;
22 run;

NOTE: The infile HYS is:
Filename=e:\hys_1995_1999.txt,
File List=('e:\hys_1995_1999.txt' 'e:\hys_2000_2004.txt'),
RECFM=V,LRECL=450

NOTE: Invalid data for doa in line 1 18-68.
NOTE: Invalid data for dod in line 1 27-68.
NOTE: Invalid data for dob in line 1 37-68.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-
1 01003960228000021199501TUE199501FRI019630800310000214739F01271126259 6144 2851 9261
87 60 226141 226146 226201 226259 2255321 22
173 684 545 6561
259 0000358133581335813358133581335813 01
345 00000003000300030003000000000000000000000000000000000000000000000000000000000000000040
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-
431 406000000639934 10
doa=. dod=. dob=. _ERROR_=1 _N_=1
NOTE: Invalid data for doa in line 2 18-68.
NOTE: Invalid data for dod in line 2 27-68.
NOTE: Invalid data for dob in line 2 37-68.
2 01003960228000021199502FRI199502FRI019560800380000214895F01213226175 6175 2768 2261
87 73 226201 226202 226160 225680 22
173 4576 684 654
259 0000148061480614806148061480614806 01
345 00000007000700070007000000000000000000000000000000000000000000000000000000000000000030
431 408000001090943 01
doa=. dod=. dob=. _ERROR_=1 _N_=2
NOTE: Invalid data for doa in line 3 18-68.
NOTE: Invalid data for dod in line 3 27-68.
NOTE: Invalid data for dob in line 3 37-68.
3 01003960228000021199501TUE199501FRI019331200610000214895F01213226182 6182 6210 2240
87 19 22
173 685 6561 7050
259 0000359133591335913359133591335913 01
345 00000003000300030003000000000000000000000000000000000000000000000000000000000000000080
431 604000000932438 10
doa=. dod=. dob=. _ERROR_=1 _N_=3
NOTE: Invalid data for doa in line 4 18-68.
NOTE: Invalid data for dod in line 4 27-68.
NOTE: Invalid data for dob in line 4 37-68.
4 01003960228000021199502WED199502WED019541000400000214727F01213226173 6173 9981 2299
87 71 222851 226200 226201 229982 224589 22
173 685 6561 5421
259 0000358133581335813358133581335813 E8700 01
345 0000000700070007000700000000000000000000000000000000000000000000000000000000000000004
431 000001383598 10
doa=. dod=. dob=. _ERROR_=1 _N_=4
NOTE: Invalid data for doa in line 5 18-68.
NOTE: Invalid data for dod in line 5 27-68.
NOTE: Invalid data for dob in line 5 37-68.
5 01003960228000021199503TUE199503SUN019230300710000214727F01213226183 6183 6256 2221
87 80 22
173 685 6561 7050
259 0000359133591335913359133591335913 01
345 00000005000500050005000000000000000000000000000000000000000000000000000000000000000030
431 808000000750965 10
doa=. dod=. dob=. _ERROR_=1 _N_=5
NOTE: Invalid data for doa in line 6 18-68.
NOTE: Invalid data for dod in line 6 27-68.
NOTE: Invalid data for dob in line 6 37-68.
6 01003960228000021199509TUE199509THU019600700350000214806F01213221820 1820 9974 9262
87 00 226201 225680 2278702 92
173 684 6561 545
259 0000354133541335413354133541335413 E8786 06
345 00000009000900090009000000000000000000000000000000000000000000000000000000000000000010
431 804000001120685 10
doa=. dod=. dob=. _ERROR_=1 _N_=6
NOTE: Invalid data for doa in line 7 18-67.
NOTE: Invalid data for dod in line 7 27-67.
NOTE: Invalid data for dob in line 7 37-67.
7 01003960228000021199506TUE199506SUN019210300740000214806F0127112179 2181 6202 22V1
87 041 22
173 684 6561
259 0000359133591335913359133591335913 01
345 00000005000500050000000000000000000000000000000000000000000000000000000000000000000030
431 6 000000542203 10
doa=. dod=. dob=. _ERROR_=1 _N_=7
NOTE: Invalid data for doa in line 8 18-68.
NOTE: Invalid data for dod in line 8 27-68.
NOTE: Invalid data for dob in line 8 37-68.
8 01003960228000021199503TUE199503SUN019431100510000214715F01213226188 6183 6188 2221
87 89 226170 226201 22
173 685 7050 6561
259 0000359133591335913359133591335913 01
345 00000005000500050005000000000000000000000000000000000000000000000000000000000000000060
431 408000000774488 10
doa=. dod=. dob=. _ERROR_=1 _N_=8
NOTE: Invalid data for doa in line 9 18-68.
NOTE: Invalid data for dod in line 9 27-68.
NOTE: Invalid data for dob in line 9 37-68.
9 01003960228000021199503TUE199504TUE019410700530000214709F01213226183 6183 9974 9299
87 676 9278833 226268 2249390 2230000 2253081 22
173 684 7050 6561
259 0000358133581335813358133581335813 E8788 01
345 00000007000700070007000000000000000000000000000000000000000000000000000000000000000030
431 406000000972663 10
doa=. dod=. dob=. _ERROR_=1 _N_=9
NOTE: Invalid data for doa in line 10 18-69.
NOTE: Invalid data for dod in line 10 27-69.
NOTE: Invalid data for dob in line 10 37-69.
10 01003960228000021199504WED199504FRI019540600400000414760F012132278930 2182 2181 2262
87 02 22
173 684 6561
259 0000359133591335913359133591335913 01
345 00000002000200020000000000000000000000000000000000000000000000000000000000000000000040
431 8 000000470441 10
doa=. dod=. dob=. _ERROR_=1 _N_=10
NOTE: Invalid data for doa in line 11 18-68.
NOTE: Invalid data for dod in line 11 27-68.
NOTE: Invalid data for dob in line 11 37-68.
11 01003960228000021199504TUE199504THU019500800440000214895F01213226268 2181 2851 2262
87 62 22
173 685 5421 5732
259 0000358133581335813358133581335813 01
345 00000002000200020002000000000000000000000000000000000000000000000000000000000000000060
431 804000000901859 10
doa=. dod=. dob=. _ERROR_=1 _N_=11
NOTE: Invalid data for doa in line 12 18-68.
NOTE: Invalid data for dod in line 12 27-68.
NOTE: Invalid data for dob in line 12 37-68.
12 01003960228000021199504TUE199504FRI019600600340000214739F01213226179 6173 6178 2261
87 71 226201 226146 22
173 685 545 6561
259 0000359133591335913359133591335913 01
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-
345 00000003000300030003000000000000000000000000000000000000000000000000000000000000000010
431 404000000769540 10
doa=. dod=. dob=. _ERROR_=1 _N_=12
NOTE: Invalid data for doa in line 13 18-68.
NOTE: Invalid data for dod in line 13 27-68.
NOTE: Invalid data for dob in line 13 37-68.
13 01003960228000021199505TUE199505SUN019160600780000214707F01213226183 6183 4019 2271
87 696 2278839 222903 223310 22
173 684 6561 7077 9774
259 0000358133591335813359133581335913 01
345 00000005000500050005000500000000000000000000000000000000000000000000000000000000000030
431 608000000631089 10
doa=. dod=. dob=. _ERROR_=1 _N_=13
NOTE: Invalid data for doa in line 14 18-68.
NOTE: Invalid data for dod in line 14 27-68.
NOTE: Invalid data for dob in line 14 37-68.
14 01003960228000021199505TUE199505SUN019490400460000214895F01213226259 6259 6202 2261
87 46 225680 226141 226170 2278833 224019 22
173 684 6561 658
259 0000359133591335913359133591335913 01
345 00000005000500050005000000000000000000000000000000000000000000000000000000000000000040
431 608000000806332 10
doa=. dod=. dob=. _ERROR_=1 _N_=14
NOTE: Invalid data for doa in line 15 18-68.
NOTE: Invalid data for dod in line 15 27-68.
NOTE: Invalid data for dob in line 15 37-68.
15 01003960228000021199505TUE199505SUN019290900650000214895F01213226182 6182 9975 9278
87 829 9278830 224019 2225000 2271590 22
173 685 6561 7050
259 0000358133581335813358133581335813 E8786 06
345 00000005000500050005000000000000000000000000000000000000000000000000000000000000000030
431 404000000685245 10
doa=. dod=. dob=. _ERROR_=1 _N_=15
NOTE: Invalid data for doa in line 16 18-68.
NOTE: Invalid data for dod in line 16 27-68.
NOTE: Invalid data for dob in line 16 37-68.
16 01003960228000021199504TUE199504FRI019470500470004614843F01213222181 2181 2800 2262
87 62 226202 22
173 685 6561 5421
259 0000358133581335813358133581335813 01
345 00000003000300030003000000000000000000000000000000000000000000000000000000000000000060
431 308000000772845 10
doa=. dod=. dob=. _ERROR_=1 _N_=16
NOTE: Invalid data for doa in line 17 18-68.
NOTE: Invalid data for dod in line 17 27-68.
NOTE: Invalid data for dob in line 17 37-68.
17 01003960228000021199504TUE199504THU019550200400000214895F01213226170 6170 2800 2261
87 78 226201 226200 226253 226250 22
173 685 6561 5421
259 0000358133581335813358133581335813 01
345 00000002000200020002000000000000000000000000000000000000000000000000000000000000000060
431 6 000000807317 10
doa=. dod=. dob=. _ERROR_=1 _N_=17
NOTE: Invalid data for doa in line 18 18-68.
NOTE: Invalid data for dod in line 18 27-68.
NOTE: Invalid data for dob in line 18 37-68.
18 01003960228000021199505TUE199505THU019630700310000214895F01213222331 2331
87
173 685
259 0000359133551335913355133591335513 03
345 00000002000200000000000000000000000000000000000000000000000000000000000000000000000040
431 6 000000389913 10
doa=. dod=. dob=. _ERROR_=1 _N_=18
NOTE: Invalid data for doa in line 19 18-68.
NOTE: Invalid data for dod in line 19 27-68.
NOTE: Invalid data for dob in line 19 37-68.
19 01003960228000021199505TUE199505SUN019561200380000214727F01213226173 6173 9981 9228
87 51 926170 222181 222362 22
173 685 6561 5421
259 0000358133581335813358133581335813 E8786 01
345 00000005000500050005000000000000000000000000000000000000000000000000000000000000000040
431 6 000000943298 10
doa=. dod=. dob=. _ERROR_=1 _N_=19
NOTE: Invalid data for doa in line 20 18-68.
NOTE: Invalid data for dod in line 20 27-68.
NOTE: Invalid data for dob in line 20 37-68.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
20 01003960228000021199505TUE199506THU019650200300000414788F01213226268 6268 6259 22
87
173 685
259 0000359133591335913359133591335913 01
345 00000002000200000000000000000000000000000000000000000000000000000000000000000000000060
431 808000000544973 10
doa=. dod=. dob=. _ERROR_=1 _N_=20
NOTE: The infile HYS is:
Filename=e:\hys_2000_2004.txt,
File List=('e:\hys_1995_1999.txt' 'e:\hys_2000_2004.txt'),
RECFM=V,LRECL=450

NOTE: 176067 records were read from the infile HYS.
The minimum record length was 450.
The maximum record length was 450.
NOTE: 182114 records were read from the infile HYS.
The minimum record length was 450.
The maximum record length was 450.
NOTE: The data set WORK.A has 358181 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.87 seconds
cpu time 0.85 seconds
SAS Employee
Posts: 6

Re: I NEED URGENT HELP With Date Format!

Jeremy,

Double check the column immediately after each of the date values in your input files.

Even though you have specified an the INFORMAT statement, the INPUT statement is using List Style input that assumes a delimiter (default is a blank/space) between each value. The informat will be applied only after the characters identifying a value have been determined.

If column 24, 33 and/or 43 is not blank, then the INPUT statement is trying to include those characters as part of the date.

The messages in the SAS log also might indicate an attempt to read values from additional columns.

If this is your problem, you will need to specify the informats in the INPUT statement, converting it into Formatted Style input. The width of 6 for the informat will identify the exact number of characters read for each date.

-Warren Repole, SAS
Super User
Posts: 10,483

Re: I NEED URGENT HELP With Date Format!

If you are getting an error message the text of the error is usually helpful.

I would try modifying your input statement to :
input doa 18-23 dod 27-32 dob 37-42;

And see if you get an error or a different one.
You may also in the case of DOB run into problems with dates before 1920 if the default of 1920 is in effect for your SAS option of YEARCUTOFF. It is likely to treat an birth before 1920 as being in 20XX instead of 19xx.
Occasional Contributor
Posts: 11

Re: I NEED URGENT HELP With Date Format!

Thanks for your suggestion ballardw. IT WORKED! Thank you all!

Jeremy.
SAS Employee
Posts: 6

Re: I NEED URGENT HELP With Date Format!

Good suggestion ballardw. Converting into Column Style in conjunction with the INFORMAT statement does the trick.
Contributor sss
Contributor
Posts: 65

Re: I NEED URGENT HELP With Date Format!

Try this


filename hys ('e:\hys_1995_1999.txt' , 'e:\hys_2000_2004.txt') lrecl=450;
data a;
infile hys;
informat doa dod dob mmddyy8.;
format doa dod dob mmddyy8.;
input
@018 doa:mmddyy8.
@027 dod:mmddyy8.
@037 dob:mmddyy8.
;
run;
Ask a Question
Discussion stats
  • 7 replies
  • 278 views
  • 0 likes
  • 5 in conversation