DATA Step, Macro, Functions and more

Usage of "+" symbol in input/put statement ?

Reply
Contributor
Posts: 22

Usage of "+" symbol in input/put statement ?

The contents of the raw data file TEAM are listed below:

--------10-------20-------30
Janice 10
Henri 11
Michael 11
Susan 12

The following SAS program is submitted:

data group;
infile 'team';
input name $15. age 2.;
file 'file-specification';
put name $15. +5 age 2.;
run;

Which one of the following describes the output created?

A. a raw data file only
B. a SAS data set named GROUP only
C. a SAS data set named GROUP and a raw data file
D. No output is generated as the program fails to execute due to errors.

 

I am not able to get a clear picture of how "+" pointer is working here. Could anyone please explain this ?

 

Thank you!

Regular Contributor
Posts: 241

Re: Usage of "+" symbol in input/put statement ?

+5 would add 5 spaces after printing name variable. As name itself is 15 char long so age would be printed after 15 characters.

You can try giving +50 insted of+5 and see the log you would understand the usage. Try the below program.

data group;
/* infile 'team'; */
input name $15. age 2.;
/* file 'file-specification'; */
 put name $15.  +5 age 2.; 
datalines;
Janice         10
Henri          11
Michael        11
Susan          12
;
Contributor
Posts: 22

Re: Usage of "+" symbol in input/put statement ?

Thank you, I tried the below code. I have understood the use of "+" symbol here, but in the output I am only getting one record which is for Henri. Why is that so?

Regular Contributor
Posts: 241

Re: Usage of "+" symbol in input/put statement ?

Above code is working fine. Try to see if you are missing something otherwise share your log.

Super User
Posts: 10,516

Re: Usage of "+" symbol in input/put statement ?

Look in your log. Do you see any messages about SAS went to the next line?

You may be requesting to read more data than exists on a single line.

 

Also when asking why something happened it often helps to post the code from the log along with any messages.

Ask a Question
Discussion stats
  • 4 replies
  • 190 views
  • 0 likes
  • 3 in conversation