BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Xamius32
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

2 REPLIES 2
Tom
Super User Tom
Super User

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;

Xamius32
Calcite | Level 5

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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