The IMSTAT procedure updates all records if there are uninitialized variables in the CODE= program


If you specify the CODE= option in an UPDATE statement and there are uninitialized variables in the SAS® program, PROC IMSTAT updates every record in the target table. To avoid unintended updates, you should initialize all variables introduced in the user supplied SAS program. To initialize a variable, use a FORMAT statement, a LENGTH statement, or an assignment statement. (This does not apply to variables already in the active table being updated.)

Failure to initialize a variable can result in all records being updated. There are no notes in the SAS Log to indicate this has happened.

Here is an example. Suppose we load the SAS data set Sashelp.cars to LASR and run the following:

proc imstat;
   table lasr.cars;
   UPDATE / code=pgm1;
quit;

where pgm1 is a fileref to a text file.
 
Suppose the text file includes the following line of code:
 
if manufacturer="Mazda" then origin="Japan";

Since MANUFACTURER does not exist in Sashelp.cars, the value of ORIGIN is updated to "Japan" in every record of Lasr.cars.

Workaround

To avoid this problem, initialize the variable MANUFACTURER in the SAS program using any of the following methods:

format manufacturer $10;
if manufacturer="Mazda" then origin="Japan";
 
length manufacturer $10;
if manufacturer="Mazda" then origin="Japan";
 
manufacturer = "Ford";
if manufacturer="Mazda" then origin="Japan";

For related notes about using the CODE= option in the UPDATE statement in PROC IMSTAT, see SAS Note 55419 and SAS Note 55420.