BookmarkSubscribeRSS Feed
nimmy_mj
Calcite | Level 5

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;

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 449 views
  • 0 likes
  • 2 in conversation