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-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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