Help using Base SAS procedures

deleting a dataset if a condition is met

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

deleting a dataset if a condition is met

Is there a way to use proc datasets and delete with certain conditions?

For example, I have dataset A and I want to delete if it the mean of one of its variables is less than a certain number. I have that mean stored in a macro variable.

I notice that it wont let me put a regular if statement in proc datasets. Is there another way to do this?

FYI, the reason I need to is I am creating hundreds of datasets with a do loop, and I only want the datasets stored if they are meeting a condition, or else too much room would be made up in the end.


Accepted Solutions
Solution
‎03-02-2013 12:48 PM
Super User
Super User
Posts: 6,502

Re: deleting a dataset if a condition is met

If you are already using a macro then you can use conditional logic (%IF %THEN etc).

Or you can just generate the code and then execute it.

For example you might do what you want with PROC SQL ;

data x;

  set sashelp.class;

run;

proc sql noprint ;

select case when (mean(age)<14) then 'proc delete data=x;run;'

            else ' ' end

into :code

from x

;

quit;

&code;

View solution in original post


All Replies
Solution
‎03-02-2013 12:48 PM
Super User
Super User
Posts: 6,502

Re: deleting a dataset if a condition is met

If you are already using a macro then you can use conditional logic (%IF %THEN etc).

Or you can just generate the code and then execute it.

For example you might do what you want with PROC SQL ;

data x;

  set sashelp.class;

run;

proc sql noprint ;

select case when (mean(age)<14) then 'proc delete data=x;run;'

            else ' ' end

into :code

from x

;

quit;

&code;

Frequent Contributor
Posts: 82

Re: deleting a dataset if a condition is met

Yea, thanks for the help, i feel dumb not thinking outside the box there.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 519 views
  • 0 likes
  • 2 in conversation