HI again.
I added another column and data and formatted the input statement as instructed. It seems to have blown up though. Here's the code: Thanks in advance:
data widepe ;
input subjectnumberstr: $9. visitmnemonic: $9. pegenap_c: & $24. peheent_c: & $24.;
datalines;
0100-1204 screening Abnormal, please specify Abnormal, please specify
0100-1204 eos/et Normal normal
0100-1205 Screening Normal normal
0100-1205 EOS/ET Normal Abnormal, please specify
;
run;
proc print data = widepe; run;
SAS Output
Obs | subjectnumberstr | visitmnemonic | pegenap_c | peheent_c |
---|---|---|---|---|
1 | 0100-1204 | screening | Abnormal, please specify | 0100-1204 eos/et Normal |
2 | 0100-1205 | Screening | Normal normal | 0100-1205 EOS/ET Normal |
Oh, totally missed the blanks in the data.
To read variable length strings that contain blanks, you need either a delimiter in the input data, or you have to enclose the strings in quotes. Then you can use the dsd option:
data widepe;
infile cards dlm="|" truncover;
input subjectnumberstr: $9. visitmnemonic: $9. pegenap_c: $24. peheent_c: $24.;
datalines;
0100-1204|screening|Abnormal, please specify|Abnormal, please specify
0100-1204|eos/et|Normal|normal
0100-1205|Screening|Normal|normal
0100-1205|EOS/ET|Normal|Abnormal, please specify
;
run;
proc print data=widepe noobs;
run;
data widepe;
infile cards dlm=" " dsd truncover;
input subjectnumberstr: $9. visitmnemonic: $9. pegenap_c: $24. peheent_c: $24.;
datalines;
0100-1204 "screening" "Abnormal, please specify" "Abnormal, please specify"
0100-1204 "eos/et" "Normal" "normal"
0100-1205 "Screening" "Normal" "normal"
0100-1205 "EOS/ET" "Normal" "Abnormal, please specify"
;
run;
proc print data=widepe noobs;
run;
Results:
subjectnumberstr visitmnemonic pegenap_c peheent_c 0100-1204 screening Abnormal, please specify Abnormal, please specify 0100-1204 eos/et Normal normal 0100-1205 Screening Normal normal 0100-1205 EOS/ET Normal Abnormal, please specify subjectnumberstr visitmnemonic pegenap_c peheent_c 0100-1204 screening Abnormal, please specify Abnormal, please specify 0100-1204 eos/et Normal normal 0100-1205 Screening Normal normal 0100-1205 EOS/ET Normal Abnormal, please specify
Remove the ampersands.
data widepe ;
input subjectnumberstr: $9. visitmnemonic: $9. pegenap_c: $24. peheent_c: $24.;
datalines;
0100-1204 screening Abnormal, please specify Abnormal, please specify
0100-1204 eos/et Normal normal
0100-1205 Screening Normal normal
0100-1205 EOS/ET Normal Abnormal, please specify
;
run;
proc print data = widepe; run;
works.
Oh, totally missed the blanks in the data.
To read variable length strings that contain blanks, you need either a delimiter in the input data, or you have to enclose the strings in quotes. Then you can use the dsd option:
data widepe;
infile cards dlm="|" truncover;
input subjectnumberstr: $9. visitmnemonic: $9. pegenap_c: $24. peheent_c: $24.;
datalines;
0100-1204|screening|Abnormal, please specify|Abnormal, please specify
0100-1204|eos/et|Normal|normal
0100-1205|Screening|Normal|normal
0100-1205|EOS/ET|Normal|Abnormal, please specify
;
run;
proc print data=widepe noobs;
run;
data widepe;
infile cards dlm=" " dsd truncover;
input subjectnumberstr: $9. visitmnemonic: $9. pegenap_c: $24. peheent_c: $24.;
datalines;
0100-1204 "screening" "Abnormal, please specify" "Abnormal, please specify"
0100-1204 "eos/et" "Normal" "normal"
0100-1205 "Screening" "Normal" "normal"
0100-1205 "EOS/ET" "Normal" "Abnormal, please specify"
;
run;
proc print data=widepe noobs;
run;
Results:
subjectnumberstr visitmnemonic pegenap_c peheent_c 0100-1204 screening Abnormal, please specify Abnormal, please specify 0100-1204 eos/et Normal normal 0100-1205 Screening Normal normal 0100-1205 EOS/ET Normal Abnormal, please specify subjectnumberstr visitmnemonic pegenap_c peheent_c 0100-1204 screening Abnormal, please specify Abnormal, please specify 0100-1204 eos/et Normal normal 0100-1205 Screening Normal normal 0100-1205 EOS/ET Normal Abnormal, please specify
Thank you Kurt for the solution, it works great. But I thought the ampersand modifier allowed for sas to read blanks within the variable length but I guess not.
@cj9000 wrote:
Thank you Kurt for the solution, it works great. But I thought the ampersand modifier allowed for sas to read blanks within the variable length but I guess not.
You are referring to this:
indicates that a character value can have one or more single embedded blanks. This format modifier reads the value from the next non-blank column until the pointer reaches two consecutive blanks, the defined length of the variable, or the end of the input line, whichever comes first.
(underline by me)
For that to work, you would have needed two blanks in succession as delimiters.
Oh I see. Okay well thank you Kurt.
This might display better, this is what I got.
SAS Output
Obs | subjectnumberstr | visitmnemonic | pegenap_c | peheent_c |
---|---|---|---|---|
1 | 0100-1204 | screening | Abnormal, | please |
2 | 0100-1204 | eos/et | Normal | normal |
3 | 0100-1205 | Screening | Normal | normal |
4 | 0100-1205 | EOS/ET | Normal | Abnormal, |
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.