BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmj636
Obsidian | Level 7

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
Astounding
PROC Star

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

6 REPLIES 6
Astounding
PROC Star

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.

andreas_lds
Jade | Level 19

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;
Coloradomis
Fluorite | Level 6

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
Kaiser Permanente Colorado

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
  • 1055 views
  • 2 likes
  • 5 in conversation