SHAZAM Community
Ask Your Question

Revision history [back]

Here is an example:

* Read some data.
sample 1 5
read var1 var2 var3  
1           2        3
1      -99999        3
1           2   -99999  
-99999      2        3
1           2        3

* Calculate means for the 4 observations and print them.
set skipmiss
stat var1 var2 var3 / mean=means
print means

* Set missing value to means for any variables we want.
set noskipmiss
if(var1.eq.-99999) var1=means:1
if(var2.eq.-99999) var2=means:2
if(var3.eq.-99999) var3=means:3

* Check the result. 5 Observations shown with means correct.
stat var1 var2 var3

The output is:

 Welcome to SHAZAM (Double Precision) v11.1 -  OCT 2014 WIN-NT   PAR=112400
 ...NOTE..CURRENT WORKING DIRECTORY IS: C:\Users\David.SOFTWAREONE\Documents\SHAZAM\Miss

 |_* Read some data.
 |_sample 1 5
 |_read var1 var2 var3
 ...NOTE..    3 VARIABLES AND        5 OBSERVATIONS STARTING AT OBS       1

 |_* Calculate means for the 4 observations and print them.
 |_set skipmiss

 |_stat var1 var2 var3 / mean=means
 NAME        N    MEAN        ST. DEV      VARIANCE     MINIMUM      MAXIMUM
 VAR1          4   1.0000     0.00000E+00 0.00000E+00   1.0000       1.0000
 VAR2          4   2.0000     0.00000E+00 0.00000E+00   2.0000       2.0000
 VAR3          4   3.0000     0.00000E+00 0.00000E+00   3.0000       3.0000

 |_print means
 MEANS
    1.000000       2.000000       3.000000

 |_* Set missing value to means for any variables we want.
 |_set noskipmiss
 |_if(var1.eq.-99999) var1=means:1
 |_if(var2.eq.-99999) var2=means:2
 |_if(var3.eq.-99999) var3=means:3

 |_* Check the result. 5 Observations shown with means correct.
 |_stat var1 var2 var3
 NAME        N    MEAN        ST. DEV      VARIANCE     MINIMUM      MAXIMUM
 VAR1          5   1.0000     0.00000E+00 0.00000E+00   1.0000       1.0000
 VAR2          5   2.0000     0.00000E+00 0.00000E+00   2.0000       2.0000
 VAR3          5   3.0000     0.00000E+00 0.00000E+00   3.0000       3.0000