Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
February 2013
(for SAS and WPS)

When we are testing something new, particularly if it is electicial or mechanical, the test equipment may have multiple inputs.

Lets say we have tested a device that has five inputs with voltage being recorded at different points on a circuit with the following data:

   TIMEPOINT   V1  V2  V3  V4  V5
       0      1.3 1.2 1.3 1.4 1.3
       1      1.3 1.2 1.3 1.3 1.3
       2      1.3 1.2 1.2 1.2 1.3
       3      1.3 1.4 1.3 1.0 1.5

Lets say we want to find if there was +/-20% change from the mean value across the timepoint - we could certainly write a piece of code similar to:

   if abs((v1-tp_mean)*100/tp_mean)>20 then
     put 'WAR' 'NING: Value V1 > +/-20% of Mean across timepoint ' timepoint;
   if abs((v2-tp_mean)*100/tp_mean)>20 then
     put 'WAR' 'NING: Value V2 > +/-20% of Mean across timepoint ' timepoint;
   if abs((v3-tp_mean)*100/tp_mean)>20 then
     put 'WAR' 'NING: Value V3 > +/-20% of Mean across timepoint ' timepoint;
   if abs((v4-tp_mean)*100/tp_mean)>20 then
     put 'WAR' 'NING: Value V4 > +/-20% of Mean across timepoint ' timepoint;
   if abs((v5-tp_mean)*100/tp_mean)>20 then
     put 'WAR' 'NING: Value V5 > +/-20% of Mean across timepoint ' timepoint;

If there are a 1000 leads then the code would be unworkable. So enter the topic of arrays.

We can define ranges of variables to be arrays, in this case we could use:

   array av(*) v1-v5;

There are some basic statistical functions, mean being of them, which will work on array values, as shown below:

   tp_mean=mean(of av(*));

Now, instead of writing multiple lines to test each value across the timepoint, we could do this in the following way:

   length msgtxt $200;
   if n(tp_mean) then do; *If mean has been calculated across the timepoint;
      do i=1 to dim(av);
         if n(av(i)) then do; *Check if value is present to avoid error;
            if abs( (av(i)-Tp_mean)*100/ Tp_mean)>20 then do;
               msgtxt='WAR'||'NING: Value '||vname(av(i))||
                      ' > +/-20% of Mean across the timepoint '||put(timepoint,3.);
               put msgtxt;

Note that this code has two conditional statements, one to check if a mean value has been calculated across the time point, and if there is a value to check against the mean.

This code can easily be modified to do 1000 leads, much more easily than the "check each variable" as we started with.

Have a safe and happy February.

Updated February 01, 2013