06-14-2016 11:51 PM - last edited on 06-15-2016 01:33 AM by Reeza
I am trying to read the data using the following code. I am not getting the output as shown in datalines statement. Only first observation I am getting exactly. For next observations all values are "Y". Please help.
input AESER $1 +1 AESDTH $1 +1 AESLIFE $1 +1 AESHOSP $1 +1 AESCONG $1 +1 AESDISAB $1 +1 AESMIE $1 +1 INFECDIS $1;
N N N N N N N N
Y N N N N N N N
Y Y N N N N Y N
Y Y Y N N N N N
06-15-2016 03:40 AM
You have different alternative that work fine
data one; input AESER $ @2 AESDTH $ @4 AESLIFE $ @6 AESHOSP $ @8 AESCONG $ @10 AESDISAB $ @12 AESMIE $ @14 INFECDIS $; datalines; N N N N N N N N Y N N N N N N N Y Y N N N N Y N Y Y Y N N N N N ; run; data one; input AESER $ AESDTH $ AESLIFE $ AESHOSP $ AESCONG $ AESDISAB $ AESMIE $ INFECDIS $; datalines; N N N N N N N N Y N N N N N N N Y Y N N N N Y N Y Y Y N N N N N ; run;
You don't need the +1 that mean skip it a column.
06-15-2016 06:45 AM
WIthin an INPUT statement:
$1 = read the contents of column 1
$1. = read the next column
Assuming you have one space between data values, you would need to change all occurrences of "$1" to "$1.".
06-15-2016 07:08 AM
While I was writing my post, @Astounding has already given the explanation ...
The explanation why your code failed is: You used column input inadvertently. SAS interpreted the specification "$1" as "read character value from column 1." Hence, all of your variables received the first letter in each line, the other letters were ignored. So, it only seemed that the first line was read correctly, because all letters happened to be equal to the first one.
What you probably wanted to do was formatted input, but informat specifications such as $1. require a period. The following INPUT statement is correct:
input AESER $1. +1 AESDTH $1. +1 AESLIFE $1. +1 AESHOSP $1. +1 AESCONG $1. +1 AESDISAB $1. +1 AESMIE $1. +1 INFECDIS $1.;
Now the "+1" pointer controls make sense, because with formatted input the blanks between the values are not skipped automatically.
The input style which skips blanks automatically (but which also requires blanks or other delimiters between data values) is list input. This in turn can be combined with informat specifications (which in your example have the main purpose of assigning type character and length 1 to the variables) and is then called modified list input:
input AESER :$1. AESDTH :$1. AESLIFE :$1. AESHOSP :$1. AESCONG :$1. AESDISAB :$1. AESMIE :$1. INFECDIS :$1.;
All of these repetitive specifications can be abbreviated by using parenthesized lists of variable names and informat specifications. In particular, modified list input could be written as:
input (AESER AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS) (:$1.);