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

Hello members,

How can I clear the results and outputs generated by the procedures within a macro? For example, for the following code. How can I only keep the data2 in within the macro and clear the intermediate results generated by % macro bydomain (conditon1=a, condition2=b); before run % macro bydomain (conditon1=c, condition2=d);?

 

Data data2;

set data1;

run;

 

% macro bydomain (conditon1, condition2);

data data2;

...

run;

 

%mend;

% macro bydomain (conditon1=a, condition2=b);

% macro bydomain (conditon1=c, condition2=d);

...

 

Thanks so much!!!

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11

Incase you you are trying to just delete specific intermediate datasets only, try this.

 

%macro bydomain (conditon1, condition2);

	proc datasets nolist lib=work mtype=data;
		delete data2;
	quit;

	data data2;
		...

		run;
%mend;

 

 

View solution in original post

5 REPLIES 5
Reeza
Super User

https://blogs.sas.com/content/iml/2015/05/28/five-reasons-ods-exclude.html

 

ODS SELECT and ODS EXCLUDE are what are needed. Or NOPRINT within the various procs. 

Reeza
Super User
I use a naming convention, with _ to start the name for all my intermediary tables. Then you can drop them using a prefix shortcut which will clear all at once.

delete _:;
ballardw
Super User

First thing would be to provide a more detailed description and possibly use different data set names in the example.

 

You only actually show one data set inside the macro, repeating the name of one outside, and it is not clear what you want to keep.

 

Typically I would use proc datasets to delete any datasets that I don't want. Either at the beginning of a macro to prevent reuse of an existing set or at the end of the macro to clean up before it ends.

 

The syntax is

Proc datasets library=somelib;

    delete datasetname;

quit;

 

you may want the NOPRINT option to reduce any output in the log

 

r_behata
Barite | Level 11

Incase you you are trying to just delete specific intermediate datasets only, try this.

 

%macro bydomain (conditon1, condition2);

	proc datasets nolist lib=work mtype=data;
		delete data2;
	quit;

	data data2;
		...

		run;
%mend;

 

 

TX_STAR
Obsidian | Level 7
I moved the following code inside the macro, the problem solved. But my solution might not be best of efficient one. What happened was When I run the second macro call (conditon1=c, condition2=d) after running the first call (conditon1=a, condition2=b), the N count of the data2 was not right. I guess sas keeps temporary data that replaced initial data2. When I call the 2nd macro, the data2 was not correct one. When I keep the following code inside the macro, each call will start with a initial data2. Hopefully this time I am clear. Thank you all.
Data data2;
set data1;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 843 views
  • 3 likes
  • 4 in conversation