Hi,
Below 2 data steps are for processing same data. Though, the data is same, the output is different. The significance of "+1" is to ignore 1 space so that the succeeding data will be considered for next variable/column. Even though, the data should not differ in output of Program 2 from that of Program 1 , I find difference in the output. Could you please explain why is it so?
Program 1:
data work.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
;
run;
Program 2:
data voter2;
input Age Party : $1. (Ques1-Ques4) ($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
;
run;
As the SAS Documentation for the INPUT Statement says:
+n moves the pointer n columns.
Consequently, you take explicit control of the input pointer in your first data step and correctly jump over the spaces. In your second data step, the data step reads just a single character (as you instruct it to) regardless of whether it is a space or not.
Consequently, if your INPUT Statement in the second data step should produce the same output as the first one, your data should look like this (i don't recommend it, but I post it for clarification)
cdata voter2;
input Age Party : $1. (Ques1-Ques4) ($1.);
datalines;
23 D 1122
45 R 5541
67 D 2433
39 R 4444
19 D 2121
75 D 3323
57 R 4344
;
run;
Or you can simply add a colon to your input statement like this
data voter2;
input Age Party : $1. (Ques1-Ques4) (:$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
;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.