DATA Step, Macro, Functions and more

Understanding "put"

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Understanding "put"

[ Edited ]
 
Given the SAS data set PERM.STUDENTS:
PERM.STUDENTS
NAME  AGE
---------  -------
Alfred  14
Alice  13
Barbara  13
Carol  14
The following SAS program is submitted:
libname perm ‘SAS data library’;
data students;
set perm.students;
file ‘file specification’;
put name $ age;
<insert statement here>
run;
The following double-spaced file is desired as output
Alfred 14
Alice 13
Barbara 13
Carol 14
Which statement completes the program and creates the desired file?
 
A. put _null_;
B. put;
C. double;
D. put/;
So, the answer is B. put; But I don't get why. I mean you already have a put statement right above. Plus, as far as I understand "put" is meant to be used for changing a numeric variable to a character variable. What would a "put" do on it's own?

Accepted Solutions
Solution
‎01-06-2016 07:28 PM
Super User
Posts: 5,518

Re: Understanding "put"

As is, the program writes the desired report, writing each line of data to a separate line.  The requirements were actually a little bit different, however, to get a double-spaced report.  So you need to make a change that will write out a blank line as well.  That's why B is needed.

View solution in original post


All Replies
Super User
Posts: 19,872

Re: Understanding "put"

It's worth learning to navigate the documentation, it has almost all the answers. 

In this case you're mixing up a STATEMENT vs a FUNCTION, both with the same name. The comparison section of the PUT statement also details this explicitly.

 

It mayalso be worth looking up SUM(), since it's another one, with both a function and statement and they behave differently as well.

 

PUT STATEMENT:

The PUT statement without arguments is called a null PUT statement. The null PUT statement
  • writes the current output line to the current location, even if the current output line is blank
  • releases an output line that is being held with a trailing @ by a previous PUT statement.
For an example, see Holding and Releasing Output Lines. For more information, see Using Line-Hold Specifiers.
 

PUT FUNCTION: 

 

Details

If the PUT function returns a value to a variable that has not yet been assigned a length, by default the variable length is determined by the width of the format.
Use the PUT function to convert a numeric value to a character value. The PUT function has no effect on which formats are used in PUT statements or which formats are assigned to variables in data sets. You cannot use the PUT function to directly change the type of variable in a data set from numeric to character. However, you can create a new character variable as the result of the PUT function. Then, if needed, use the DROP statement to drop the original numeric variable, followed by the RENAME statement to rename the new variable back to the original variable name.

Comparisons

The PUT statement and the PUT function are similar. The PUT function returns a value using a specified format. You must use an assignment statement to store the value in a variable. The PUT statement writes a value to an external destination (either the SAS log or a destination, that you specify).
Contributor
Posts: 24

Re: Understanding "put"

You do raise a valid point, that I could have reviewed the documentation, but in this case, I would have actually been lost in the PUT function. I honestly, didn't know you're allowed to use the same function and as a statement. Knowing that is a useful bit of information. Thought I knew "PUT" quite well, but it seems that I only knew the function, not the statement. Thanks for your reply.
Super User
Super User
Posts: 7,078

Re: Understanding "put"

Just to be more confusing the there are actually two SUM() functions.

There is the SQL aggregate function SUM() that takes one argument and produces the sum across rows.

There is data step function SUM() that takes two or more arguments and produces the sum of its arguments, which could be thought of as producing the sum across columns instead of rows.

Solution
‎01-06-2016 07:28 PM
Super User
Posts: 5,518

Re: Understanding "put"

As is, the program writes the desired report, writing each line of data to a separate line.  The requirements were actually a little bit different, however, to get a double-spaced report.  So you need to make a change that will write out a blank line as well.  That's why B is needed.

New User
Posts: 1

Re: Understanding "put"

Posted in reply to Astounding
 
It says,
 
Print the data set EXPREV. EXPREV contains information about a company's product order type and price per unit for two months. DOUBLE inserts a blank line between observations. The DOUBLE option has no effect on the HTML output.
proc print data = exprev double;
 
Does this not mean that the answer should actually be double and not put? 
 
 

 

Super User
Super User
Posts: 7,078

Re: Understanding "put"

Posted in reply to preetimangtani

preetimangtani wrote:
 
It says,
 
Print the data set EXPREV. EXPREV contains information about a company's product order type and price per unit for two months. DOUBLE inserts a blank line between observations. The DOUBLE option has no effect on the HTML output.
proc print data = exprev double;
 
Does this not mean that the answer should actually be double and not put? 
 
 

 


The DOUBLE keyword in the article you linked to is an option on the PROC PRINT statement and not a stand alone statement like in the choices listed in the original problem.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 1569 views
  • 6 likes
  • 5 in conversation