Help using Base SAS procedures

question about an input statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

question about an input statement

"data voter;

input Age Party : $1. (Ques1-Ques4) ($1. +1);

datalines;

23 D 1 1 2 2

45 R 5 5 4 1

67 D 2 4 3 3

39 R 4 4 4 4

19 D 2 1 2 1

75 D 3 3 2 3

57 R 4 3 4 4

;"

Above is a part of code I quoted. What I cannot understand is the "+1" following "$1." in second line.

What is its function? If without it, what will be wrong?


Accepted Solutions
Solution
‎09-29-2011 04:11 AM
Super User
Posts: 9,691

Re: question about an input statement

Party : $1.

Means to eat a character, colon means to stop read when encounter a delimiter blank ,

Because it is list input method, so point will move a unit forward.

(Ques1-Ques4) ($1. +1);

is equal to     Ques1 $1. +1  Ques2 $1. +1   Ques3 $1. +1    Ques4 $1. +1

Ksharp

View solution in original post


All Replies
PROC Star
Posts: 7,366

Re: question about an input statement

The way it is written, yes, it is needed.  Conversely, something like the following would also work:

data voter;

  informat party ques1-ques4 $1.;

  input Age Party Ques1-Ques4;

  datalines;

23 D 1 1 2 2

45 R 5 5 4 1

67 D 2 4 3 3

39 R 4 4 4 4

19 D 2 1 2 1

75 D 3 3 2 3

57 R 4 3 4 4

;

You have a number of options and capabilities when it comes to inputting data in SAS.  For a nice overview, take a look at:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm

Solution
‎09-29-2011 04:11 AM
Super User
Posts: 9,691

Re: question about an input statement

Party : $1.

Means to eat a character, colon means to stop read when encounter a delimiter blank ,

Because it is list input method, so point will move a unit forward.

(Ques1-Ques4) ($1. +1);

is equal to     Ques1 $1. +1  Ques2 $1. +1   Ques3 $1. +1    Ques4 $1. +1

Ksharp

Occasional Contributor
Posts: 12

Re: question about an input statement

I have one ques..

If I am not giving +1, then it is not taking any values for Ques2 and Ques4, By Default how it is working..plz explain?

Trusted Advisor
Posts: 2,113

Re: question about an input statement

Narenda,

Without the +1, the blanks between the numbers are read as data.  If you look carefully, you would see that the value for Ques3 is actually the value that was meant for Ques2 in the original.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 501 views
  • 3 likes
  • 5 in conversation