0
votes

Am I right that, to add a new column to an existing SAS dataset, I use the Alter Table statement (and, for populating the new column, the Update statement) in proc sql? If so, what are the equivalent statements in proc iml (or can it even be done in IML)?

1
IML doesn't really have a concept of 'dataset', it has a matrix. Can you post an example of what you're asking? And, right now you're asking more than one question. Are you specifically asking the IML question and the rest is just extraneous information?Joe
Personally I wouldn't use ALTER table and Update to add a variable to a table. I would make a new table that contains the variables I want from the old table and merges on or calculates the new variable. In IML I would do the same thing. Make a new matrix by concatenating the old matrix with a new matrix that had compatible dimensions.Tom
How do I make sure that the values in the new table being concatenated line up with the corresponding values from the old dataset?Mhoram

1 Answers

0
votes

It sounds like you are asking about horizontal concatentation. You can use the concatenation operator (||) to append the columns of one matrix to another, provided that both matrices have the same number of rows. For example, the following statement concatenate a 2x1 vector to a 2x3 matrix. The result is a 2x4 matrix:

proc iml;
x = {1 2 3,
     4 5 6};
y = {7, 8};
z = x || y;
print z;

Be aware, however, that this allocates a new matrix (z) and copies over the contents of the x and y matrices. Therefore it is not as efficient as creating a 4x2 matrix from the beginning and then using subscrits to fill the columns. For details, see the article "Friends don't let friends concatenate results inside a loop."