BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10

hello

how could I delete all macro variables defined by user during program execution

thanks in advance for your help

Regards

Nass

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

You can take a look at the sashelp.vmacro view and adapt the following program to your needs.

 

%let x=1;
%let y=hello;

data _NULL_;
set sashelp.vmacro(where=(scope='GLOBAL'));
call execute(catx(' ','%nrstr(%symdel)',name,';'));
run;

View solution in original post

4 REPLIES 4
yabwon
Onyx | Level 15

Check out the `%symdel` statement, doc. here: https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p1vtk6flp9vpfzn14kkxolcnggzy.htm&docse...

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Nasser_DRMCP
Lapis Lazuli | Level 10
Thanks Bart for your quick respons
but I would like to delete without specifying the variables names.
then I could call the same command for programmes without knowing the varaibles names.
thanks
yabwon
Onyx | Level 15

you could try with something like this:

%let a = 1;
%let b = 2;
%let c = 3;


options notes source;

%macro symdelALL();
%local _OPTIONS_ _TEMPFILE_;
%let _OPTIONS_ = %sysfunc(getoption(notes)) %sysfunc(getoption(source));
%let _TEMPFILE_ = _%sysfunc(datetime(),hex7.);
options NOnotes NOsource;
filename &_TEMPFILE_. TEMP lrecl = 512;

proc printto log = &_TEMPFILE_.;
run;
%put _user_;
proc printto log = log;
run;

data _null_;
  length vname $ 2048;
  retain vname " ";
  infile &_TEMPFILE_. lrecl = 512 end=EOF;
  input;
  if "GLOBAL" =: _infile_ then vname=catx(" ", vname, scan(_INFILE_,2," "));
  if EOF then call execute('%nrstr(%symdel ' || strip(vname) || " / nowarn;)");
run;
filename &_TEMPFILE_.;
options &_OPTIONS_.;
%mend symdelALL;

%put _user_;
%symdelALL()
%put _user_;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



gamotte
Rhodochrosite | Level 12

Hello,

 

You can take a look at the sashelp.vmacro view and adapt the following program to your needs.

 

%let x=1;
%let y=hello;

data _NULL_;
set sashelp.vmacro(where=(scope='GLOBAL'));
call execute(catx(' ','%nrstr(%symdel)',name,';'));
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 832 views
  • 0 likes
  • 3 in conversation