PING  0.9
Statistical data handling and processing in production environment
ds_delete

Conditionally delete observations and drop variable(s) from a given dataset.

%ds_delete(dsn, var=, cond=, obs=, firstobs=0, lib=WORK);

Arguments

  • dsn : a dataset reference;
  • var : (option) List of variable(s) to delete (drop) from the dataset; if more variables are to be deleted, var should be defined as an unformatted list; default: not used;
  • cond : (option) an expression that resolves to a boolean (0/1) so that all observations for which cond is true (1) will be deleted; default: 0, i.e. no observations is deleted;
  • firstobs, obs : (option) indexes of the first and the last observations to consider for the delete operation resp.; all obsevation whose index is <firstobs or >obs will be automatically deleted; see DATA step options; by default, options are not used;
  • lib : (option) name of the input library; by default: empty, i.e. WORK is used.

Returns

The table dsn is updated with the conditional deletion.

Examples

Let us consider the following _dstest31 table:

geo value unit
BE 0 EUR
AT 0.1 EUR
BG 0.2 NAC
LU 0.3 EUR
FR 0.4 NAC
IT 0.5 EUR

we will delete all VALUEs and keep only observations for which UNIT is EUR:

%ds_delete(_dstest31, var=value, cond=%quote(unit="EUR"));

so that we have:

geo unit
BG NAC
FR NAC

Note that the command can be used to delete more than one variable at a time, e.g.:

%ds_delete(_dstest31, var=value unit, cond=%quote(unit="EUR"));

will return instead:

geo
BG
FR

Run macro %_example_ds_delete for more examples.

Notes

  1. In short, the macro sequentially runs two operations that summarizes to the following DATA step:
DATA &lib..&dsn (DROP=&var);
SET &lib..&dsn(FIRSTOBS=&firstobs OBS=&obs);
IF &cond THEN DELETE;
run;
  1. It shall be noticed that in practice: first the options firstobs and obs are applied, then the condition cond is evaluated (though it occurs inside a unique DATA step), and then the variable var is dropped from the dataset. This matters in the cases where cond is an expression based on var values.

References

  1. "Selecting and restricting observations".
  2. Gupta, S. (2006): "WHERE vs. IF statements: Knowing the difference in how and when to apply".

See also

%ds_check, %ds_isempty, %var_check, DELETE, DROP.