| Date: | Fri, 6 Feb 2004 13:10:14 -0500 |
| Reply-To: | diskin.dennis@KENDLE.COM |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Dennis Diskin <diskin.dennis@KENDLE.COM> |
| Subject: | Re: reading delimited data |
|
| Content-Type: | text/plain; charset="us-ascii" |
|---|
Karen,
When you specify a format with a length on the input line, SAS starts the
following variable at the next column which, is a delimiter, so it sees
the variable as a null. Try puttiong the input formats in an INFORMAT like
this:
data TEMP;
length id $10 vdate 8 timetext $10 ddate 8 dtimetext $10 gender $1 ageyears 8;
informat vdate ddate yymmdd10.;
infile cards DSD delimiter='7C'x TRUNCOVER;
input id vdate timetext ddate dtimetext gender ageyears ;
format vdate ddate mmddyy10.;
cards;
2y3034821c|2000/07/05|03:05 AM|2000/03/29|11:52 PM|M|49
72db1acd0f|2000/12/16|11:03 AM|||M|
bb4e2a0718|2000/07/28||||M|48
6d59ff5c05|2000/02/10|11:13 PM|||F|37
ff1361cc92|2000/09/25|01:16 AM|||M|51
4cbc8e3bcc|||||M|51
3a30f0c61c|2000/03/29|04:37 PM||||
f7331c4b6e|2000/12/27|03:16 PM|||F|47
d5f747e0dd|2000/08/09|10:00 AM|||F|47
077739b87d|2000/12/18|04:55 PM|||F|57
4ff29e7e20|2000/12/17|00:12 AM||||68
nf8ss7f4db|2000/03/28|03:37 AM|||F|59
a118a49ba7|2000/06/14|09:02 PM|||F|57
6780 77b80|2000/07/10|07:37 PM|||F|57
nhk034857b|2000/05/08|03:37 PM|||M|26
;
run;
proc print;
run;
Karen Olson <karen.olson@TCH.HARVARD.EDU>
Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
02/06/2004 12:59 PM
Please respond to Karen Olson
To: SAS-L@LISTSERV.UGA.EDU
cc:
Subject: reading delimited data
I have a delimited data file (delimited with |) that contains id, date,
time, another date, another time, gender, and age.
I tried to read it with the following code:
data TEMP;
length id $10. vdate 8. timetext $10. ddate 8. dtimetext $10.
gender $1. ageyears 8.;
infile 'TEMP.TXT' DSD delimiter='7C'x TRUNCOVER;
input id $ vdate yymmdd10. timetext $ ddate yymmdd10. dtimetext $
gender $ ageyears ;
format vdate ddate mmddyy10.;
run;
However, I am not reading the data correctly and am having the most
trouble reading the time variables.
What am I doing wrong?
Thanks,
Karen Olson
Children's Hospital Boston
karen.olson@tch.harvard.edu
--------------------------------
This is my sample data file:
--------------------------------
2y3034821c|2000/07/05|03:05 AM|2000/03/29|11:52 PM|M|49
72db1acd0f|2000/12/16|11:03 AM|||M|
bb4e2a0718|2000/07/28||||M|48
6d59ff5c05|2000/02/10|11:13 PM|||F|37
ff1361cc92|2000/09/25|01:16 AM|||M|51
4cbc8e3bcc|||||M|51
3a30f0c61c|2000/03/29|04:37 PM||||
f7331c4b6e|2000/12/27|03:16 PM|||F|47
d5f747e0dd|2000/08/09|10:00 AM|||F|47
077739b87d|2000/12/18|04:55 PM|||F|57
4ff29e7e20|2000/12/17|00:12 AM||||68
nf8ss7f4db|2000/03/28|03:37 AM|||F|59
a118a49ba7|2000/06/14|09:02 PM|||F|57
6780 77b80|2000/07/10|07:37 PM|||F|57
nhk034857b|2000/05/08|03:37 PM|||M|26
--------------------------------
This is what my code yields:
--------------------------------
Obs id vdate timetext ddate dtimetext gender ageyears
1 2y3034821c 07/05/2000 . 000/03/29 1 .
2 72db1acd0f 12/16/2000 . M .
3 bb4e2a0718 07/28/2000 . .
4 6d59ff5c05 02/10/2000 . F 37
5 ff1361cc92 09/25/2000 . M 51
6 4cbc8e3bcc . . .
7 3a30f0c61c 03/29/2000 . .
8 f7331c4b6e 12/27/2000 . F 47
9 d5f747e0dd 08/09/2000 . F 47
10 077739b87d 12/18/2000 . F 57
11 4ff29e7e20 12/17/2000 . 68
12 nf8ss7f4db 03/28/2000 . F 59
13 a118a49ba7 06/14/2000 . F 57
14 6780 77b80 07/10/2000 . F 57
15 nhk034857b 05/08/2002 . M 26
|