Search code examples
sassas-iml

SAS IML append vector to dataset


I'm trying to append a new vector to a dataset in SAS IML

I create these data:

proc iml;
x = {1 2 3};
y = {1 2 3};
create data1 var {x y};
append;
close data1;
quit;

And then I would like to append new vector "z" to the dataset

proc iml;
use data1;
read all;
z = x + y;
create data1 var {x y z};
quit;

But this gives me the error "ERROR: The data set WORK.DATA1 is in use, cannot be created"


Solution

  • You need to first close data set data1 before you can do another create of data set data1.

    proc iml;
    use data1;
    read all var{x} into x;
    read all var{y} into y;
    close data1;
    z = x + y;
    create data1 var {x y z};
    append;
    quit;