Add Variables to a DataObject

If the DataObject is already created, you can add a new variable to the DataObject by using the AddVar method. For example, add the following statements to the SAS/IML Studio program from the previous section, and select ProgramRun from the main menu.

   z = {-1, 1, 0, 0, 1}; 
   dobjMatrix.AddVar( "z", z); 
   DataTable.Create( dobjMatrix ); 

The result is a DataObject with three variables (the new variable is z) and five observations. It is an error to try to add a new variable that has a different number of observations than the DataObject.

There is also a DataObject method, called the AddVars method, that enables you to add several variables in a single call.