BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Durlov
Obsidian | Level 7
 
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?
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

6 REPLIES 6
Reeza
Super User

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).
Durlov
Obsidian | Level 7
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.
Tom
Super User Tom
Super User

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.

Astounding
PROC Star

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.

preetimangtani
Calcite | Level 5
 
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? 
 
 

 

Tom
Super User Tom
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 4852 views
  • 8 likes
  • 5 in conversation