Manipulate a dataset without recreate it

Reply
Contributor
Posts: 43

Manipulate a dataset without recreate it

Hi,

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.

Super Contributor
Posts: 416

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: 7,727

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:

http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n0g9jfr4x5hgsfn...

 

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.

Ask a Question
Discussion stats
  • 2 replies
  • 266 views
  • 0 likes
  • 3 in conversation