03-31-2016 03:43 AM
sometimes I have a dataset with indexes, contraints, etc, and I need to edit its data. So I may need to modify some values, to delete rows, to calculate a new column, and so on. This can be easily done in one step with a data step, i.e.:
data X; set X; if (a = 1) then b = 99; /* updating values */ if (a = 2) then delete; /* deleting rows */ q = a + 2; /* adding a new calculated column */ run;
However, in this way I re-create the dataset X, so I lose all its properties (indexes, constraints, etc.).
Is there a way as simple as the example above to preserve such properties?
I prefer not to use proc sql in these cases for performance reason (dataset are huge).
Thanks a lot.
03-31-2016 05:20 AM
The MODIFY statement may be just what you're looking for.
Put in place of the SET statement. But not after reading the docs: MODIFY Statement
Good luck, Jan.
03-31-2016 05:29 AM
Well there is a modify statement in SAS Datastep. You would need to create a small dataset with your updates, and then apply them to the main dataset:
However this doesn't allow new variables to be added.
SQL can do most of this, your point on performance shouldn't be a problem with these updates:
proc sql; alter table have add q; update have set b=99 where a=1; delete from have where a=2; update have set q=a+2; quit;
Which ever way you go, its going to take some resource.