Manipulate a dataset without recreate it

Posts: 48

Manipulate a dataset without recreate it


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 */

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.

Valued Guide
Posts: 533

Re: Manipulate a dataset without recreate it

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.

Super User
Super User
Posts: 9,599

Re: Manipulate a dataset without recreate it

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;

Which ever way you go, its going to take some resource.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation