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!
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.
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
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.
Thank you!
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;
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=====================
========================OUTPUT=====================
Obs | val | val_sum |
1 | 10 | 10 |
2 | 20 | 30 |
3 | 30 | 60 |
4 | . | 60 |
Thank you so much this was helpful.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.