DATA Step, Macro, Functions and more

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

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

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!


Accepted Solutions
Solution
‎08-29-2017 11:37 AM
Super User
Posts: 6,637

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.

View solution in original post


All Replies
Super User
Posts: 23,321

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

Solution
‎08-29-2017 11:37 AM
Super User
Posts: 6,637

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.

Contributor
Posts: 26

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

Posted in reply to Astounding

Thank you!

Valued Guide
Posts: 522

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;
New Contributor
Posts: 2

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)Smiley SadColumn).
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
Kaiser Permanente Colorado
Contributor
Posts: 26

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

Posted in reply to Coloradomis

Thank you so much this was helpful.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 216 views
  • 2 likes
  • 5 in conversation