I am looking to take a column off an existing dataset (Weight in the example below), do logic on it in IML and then add a new column to the existing data set (or create a new dataset with all the columns from the original and the new column). Thank you.
proc iml;
ds = "Sashelp.Class";
use (ds);
read all var _NUM_ into X;
close (ds);
...do some vector logic using Weight...
...add the new column vector back onto the original dataset...
run;
The easiest way is to create a new data set that has the new column(s) and then merge with the original data:
proc iml;
ds = "Sashelp.Class";
use (ds);
read all var _NUM_ into X[c=VarNames];
close (ds);
print varNames;
weight = X[,'Weight'];
NewWeight = 2*weight;
create NewCol var "NewWeight";
append;
close;
QUIT;
data newClass;
merge Sashelp.Class NewCol;
run;
proc print data=NewClass; run;
The easiest way is to create a new data set that has the new column(s) and then merge with the original data:
proc iml;
ds = "Sashelp.Class";
use (ds);
read all var _NUM_ into X[c=VarNames];
close (ds);
print varNames;
weight = X[,'Weight'];
NewWeight = 2*weight;
create NewCol var "NewWeight";
append;
close;
QUIT;
data newClass;
merge Sashelp.Class NewCol;
run;
proc print data=NewClass; run;
Why not use a table?
proc iml;
t = TableCreateFromDataSet("Sashelp", "Class");
NewWeight = TableGetVarData(t, "Weight")#2;
call TableAddVar(t, "NewWeight", NewWeight);
call TableWriteToDataSet(t, "work", "NewClass");
quit;
proc print data=NewClass;
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.