SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Bulleride
Obsidian | Level 7

 ----|----10---|----20---|----30

1901 2

1905 1

1910 6
1925 .
1941 1
The following SAS program is submitted and references the raw data file above:
data coins;
infile'file-specification';
input year quantity;
<insert statement(s) here>
run;
Which one of the following completes the program and produces a non-missing
value for the variable TOTQUANTITY in the last observation of the output data
set?  (here quantity is the numbers 2,1,6,.,1 in the dataset)

A. totquantity + quantity;
B. totquantity = sum(totquantity + quantity);
C. totquantity 0;
sum totquantity;
D. retain totquantity 0;
totquantity = totquantity = quantity;

 

Ans –A 

Doubt: As A is not in a SUM or RETAIN statement won't it cause missing value as '.'; or does this expression accumulates and retains the values?

1 REPLY 1
mohamed_zaki
Barite | Level 11

This is called Sum Statment in SAS. And it is equivalent to using the SUM function and the RETAIN statement.

As you noticed in your data you have missing values so to do the cumulative summation you need the SUM function and Retain or as shortcut you can use the SUM statment.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1991 views
  • 1 like
  • 2 in conversation