BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear sir,

 

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.

 

Thank you.

 

data one;
input AESER $1 +1 AESDTH $1 +1 AESLIFE $1 +1 AESHOSP $1 +1 AESCONG $1 +1 AESDISAB $1 +1 AESMIE $1 +1 INFECDIS $1;
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;

3 REPLIES 3
arodriguez
Lapis Lazuli | Level 10

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. 

Astounding
PROC Star

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.".

FreelanceReinh
Jade | Level 19

Hello @knveraraju91,

 

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.);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1038 views
  • 3 likes
  • 4 in conversation