Obsidian | Level 7

## Base Certification Assignment Statement, Sum Statement, Sum Function, and missing values

Hi I am studying for the Base Certification Exam and I have a quetion over Assignment Statement, Sum Statement, Sum Function, and missing values. Assignment Statements are all statements in the form of A=a+b and will always produce a missing value if a missing value is present in the data, correct? Sum statements a+b and sum functions sum(of a,b) will ignore missing values if present in the data, correct? If a statement consists of a combination of the two Avg=mean(of a,b) this is ultimately in the form of an assignment statement so the missing value would produce missing data for the remaining output - is this correct?

I appreciate any help or reference you can provide me for clarification on this material.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PROC Star

## Re: Base Certification Assignment Statement, Sum Statement, Sum Function, and missing values

You were doing great until you got to the MEAN function.  The MEAN function ignores missing arguments, and computes the mean of the non-missing arguments.

6 REPLIES 6
Super User

## Re: Base Certification Assignment Statement, Sum Statement, Sum Function, and missing values

Look up each statement and review it's specific documentation.

https://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#titlepage.htm

PROC Star

## Re: Base Certification Assignment Statement, Sum Statement, Sum Function, and missing values

You were doing great until you got to the MEAN function.  The MEAN function ignores missing arguments, and computes the mean of the non-missing arguments.

Obsidian | Level 7

Thank you!

## Re: Base Certification Assignment Statement, Sum Statement, Sum Function, and missing values

You could write a simple data step and see what happens.

There is no need ot use of in sum or mean function while not using wildcards. The functions sum and mean ignore missing values.

``````data work.test;
input a b;

c = a + b;
d = sum(a, b);
e = mean(a, b);
f = a;
g = b;
f + g;

label
c = 'a+b'
d = 'sum(a, b)'
e = 'mean(a, b)'
f = 'f=b; f+g'
g = 'b'
;

datalines;
. 1
1 .
1 1
. .
;
run;

proc print data=work.test label;
run;``````
Fluorite | Level 6

## Re: Base Certification Assignment Statement, Sum Statement, Sum Function, and missing values

Hello KMJ,

You are correct.  Assignment statements result in NULL if any operand is a NULL value.  Sum statements and Sum functions do ignore NULL values in their final result.   Regarding your last question, The functions, operands and operators on the right side of the equation drive the result.  In your example, AVG is assigned the result since the MEAN function parameters that are NULL are ignored.  If you tried to subtraction or add a NULL value, AVG=MEAN(of a1=a4)  - null_val, then the AVG would be NULL.

This code demonstrates each of your questions:

DATA x;
*** Assignment question ***;
x=10;
y=.;
A=x+y;

PUT "=================";
PUT A= ;

*** SUM() Question ***;
d1=10;
d2=20;
d3=30;
d4=.;

D=SUM( of d1-d4);
PUT D=;

*** Combining Assignment and Function statements Question***;
E=MEAN(of d1-d4);
PUT E=;

F=MEAN(of d1-d4) - d4;
PUT F=;
PUT "=================";

RUN;
*** SUM Statement Question***;
DATA x2;
INFILE DATALINES;
LENGTH val 8;
INPUT val ;
val_sum + val; ** <- sum statement **;
DATALINES;
10
20
30
.
;
RUN;
PROC PRINT; RUN;

DATALINES;
10
20
30
.
;
RUN;
PROC PRINT; RUN;

========================LOG=====================

=================
A=.
D=60
E=20
F=.
=================

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 66:7 1 at 84:21
NOTE: The data set WORK.X has 1 observations and 10 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

========================OUTPUT=====================

 Obs val val_sum 1 10 10 2 20 30 3 30 60 4 . 60
Allen Malone
Institute for Health Research