<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: delete macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883417#M349042</link>
    <description>&lt;P&gt;How can I tell SAS-&lt;/P&gt;
&lt;P&gt;step 1-Recognize the macro vars that are user defined (It means that&amp;nbsp; user created them and they were not created automatically)&lt;/P&gt;
&lt;P&gt;step 2-Delete the macro vars from step 1&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jul 2023 11:07:18 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2023-07-04T11:07:18Z</dc:date>
    <item>
      <title>delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883407#M349033</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to delete all user defined macro variables.&lt;/P&gt;
&lt;P&gt;I also want to delete all data sets in work library.&lt;/P&gt;
&lt;P&gt;I get error that &lt;CODE class=" language-sas"&gt;automatic macro variable are&amp;nbsp;on&amp;nbsp;attempt&amp;nbsp;to&amp;nbsp;be&amp;nbsp;deleted.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;My&amp;nbsp;question--How&amp;nbsp;can&amp;nbsp;I&amp;nbsp;ask&amp;nbsp;to&amp;nbsp;delete&amp;nbsp;only&amp;nbsp;user&amp;nbsp;defined&amp;nbsp;macro&amp;nbsp;variables?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_ALL.
NOTE: Invalid argument to function SYMDEL('SYS_SQL_IP_A'[12 of 32 characters shown]) at line 26 column 36.
scope=GLOBAL name=SYS_SQL_IP_ALL offset=0 value=-1 _ERROR_=1 _N_=8
ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_STMT.
NOTE: Invalid argument to function SYMDEL('SYS_SQL_IP_S'[12 of 32 characters shown]) at line 26 column 36.
scope=GLOBAL name=SYS_SQL_IP_STMT offset=0 value=  _ERROR_=1 _N_=9
ERROR: Attempt to delete automatic macro variable SYS_TPT_USED.
NOTE: Invalid argument to function SYMDEL('SYS_TPT_USED'[12 of 32 characters shown]) at line 26 column 36.
scope=GLOBAL name=SYS_TPT_USED offset=0 value=NO _ERROR_=1 _N_=10
ERROR: Attempt to delete automatic macro variable SYSDBMSG.
NOTE: Invalid argument to function SYMDEL('SYSDBMSG    '[12 of 32 characters shown]) at line 26 column 36.
scope=GLOBAL name=SYSDBMSG offset=0 value=  _ERROR_=1 _N_=27
ERROR: Attempt to delete automatic macro variable SYSDBRC.
NOTE: Invalid argument to function SYMDEL('SYSDBRC     '[12 of 32 characters shown]) at line 26 column 36.
scope=GLOBAL name=SYSDBRC offset=0 value=0 _ERROR_=1 _N_=28
ERROR: Attempt to delete automatic macro variable AFDSID.
NOTE: Invalid argument to function SYMDEL('AFDSID      '[12 of 32 characters shown]) at line 26 column 36.
scope=AUTOMATIC name=AFDSID offset=0 value=0 _ERROR_=1 _N_=29
ERROR: Attempt to delete automatic macro variable AFDSNAME.
NOTE: Invalid argument to function SYMDEL('AFDSNAME    '[12 of 32 characters shown]) at line 26 column 36.
scope=AUTOMATIC name=AFDSNAME offset=0 value=  _ERROR_=1 _N_=30
ERROR: Attempt to delete automatic macro variable AFLIB.
NOTE: Invalid argument to function SYMDEL('AFLIB       '[12 of 32 characters shown]) at line 26 column 36.
scope=AUTOMATIC name=AFLIB offset=0 value=  _ERROR_=1 _N_=31
ERROR: Attempt to delete automatic macro variable AFSTR1.
NOTE: Invalid argument to function SYMDEL('AFSTR1      '[12 of 32 characters shown]) at line 26 column 36.
scope=AUTOMATIC name=AFSTR1 offset=0 value=  _ERROR_=1 _N_=32
ERROR: Attempt to delete automatic macro variable AFSTR2.
NOTE: Invalid argument to function SYMDEL('AFSTR2      '[12 of 32 characters shown]) at line 26 column 36.
scope=AUTOMATIC name=AFSTR2 offset=0 value=  _ERROR_=1 _N_=33
2                                                          The SAS System                                 08:10 Monday, July 3, 2023

ERROR: Attempt to delete automatic macro variable FSPBDV.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=5;
%let y=100;
%let branch=876;

proc sql ;
create table macro_Vars as
select *
from dictionary.macros
; 
quit;

data tbl;
input ID age;
cards;
1 45
2 18
;
run;


%macro clearALL;
/*delete macro variables*/
data _null_;
set macro_Vars;
call symdel(name);
run;

/*clear libnames and filenames*/
libname _ALL_ clear;
filename _ALL_ clear;

/*deletes all datasets from work*/
proc datasets lib=work kill noprint;
run;
%mend clearALL;
%clearALL&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jul 2023 10:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883407#M349033</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-07-04T10:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883408#M349034</link>
      <description>&lt;P&gt;Please do NOT (in this thread, and in the future) separate the errors from the code that produces them. Show us the ENTIRE log for the DATA step or PROC that produces the errors; we need to see the log from the start of the DATA step or PROC all the way down to the last ERROR message/WARNING/NOTE for that data step or PROC; do not show us partial logs.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 10:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883408#M349034</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-04T10:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883409#M349035</link>
      <description />
      <pubDate>Tue, 04 Jul 2023 11:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883409#M349035</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-07-04T11:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883410#M349036</link>
      <description>&lt;P&gt;Please read carefully. I said, very specifically: "Show us the ENTIRE log &lt;FONT color="#FF0000"&gt;for the DATA step or PROC that produces the errors&lt;/FONT&gt;"&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 10:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883410#M349036</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-04T10:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883412#M349038</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1                                                          The SAS System                                13:48 Tuesday, July 4, 2023

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HTMLBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&amp;amp;sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         %macro clearALL;
27         /*delete macro variables*/
28         data _null_;
29         set macro_Vars;
30         call symdel(name);
31         run;
32         /*clear libnames and filenames*/
33         libname _ALL_ clear;
34         filename _ALL_ clear;
35         /*deletes all datasets from work*/
36         proc datasets lib=work kill noprint;
37         run;
38         %mend clearALL;
39         %clearALL

ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_ALL.
NOTE: Invalid argument to function SYMDEL('SYS_SQL_IP_A'[12 of 32 characters shown]) at line 39 column 36.
scope=GLOBAL name=SYS_SQL_IP_ALL offset=0 value=-1 _ERROR_=1 _N_=9
ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_STMT.
NOTE: Invalid argument to function SYMDEL('SYS_SQL_IP_S'[12 of 32 characters shown]) at line 39 column 36.
scope=GLOBAL name=SYS_SQL_IP_STMT offset=0 value=  _ERROR_=1 _N_=10
ERROR: Attempt to delete automatic macro variable SYSDBMSG.
NOTE: Invalid argument to function SYMDEL('SYSDBMSG    '[12 of 32 characters shown]) at line 39 column 36.
scope=GLOBAL name=SYSDBMSG offset=0 value=  _ERROR_=1 _N_=29
ERROR: Attempt to delete automatic macro variable SYSDBRC.
NOTE: Invalid argument to function SYMDEL('SYSDBRC     '[12 of 32 characters shown]) at line 39 column 36.
scope=GLOBAL name=SYSDBRC offset=0 value=0 _ERROR_=1 _N_=30
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 31 observations read from the data set WORK.MACRO_VARS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jul 2023 10:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883412#M349038</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-07-04T10:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883414#M349039</link>
      <description>&lt;P&gt;What do you think this means?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_ALL&lt;/PRE&gt;
&lt;P&gt;It means you can't delete this macro variable because it is a SYSTEM generated macro variable. So don't try to delete it. How can you tell which variables are system generated? You look at the data set you created called macro_vars, and you look at the errors generated; that should give you a clue.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 10:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883414#M349039</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-04T10:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883417#M349042</link>
      <description>&lt;P&gt;How can I tell SAS-&lt;/P&gt;
&lt;P&gt;step 1-Recognize the macro vars that are user defined (It means that&amp;nbsp; user created them and they were not created automatically)&lt;/P&gt;
&lt;P&gt;step 2-Delete the macro vars from step 1&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 11:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883417#M349042</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-07-04T11:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883429#M349048</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1688470991182.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85545i586662AC169674E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1688470991182.png" alt="Patrick_0-1688470991182.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Just be aware that this will also delete some of the global scope macro variable SAS creates during session invocation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could as the very first step in a SAS session run the query and store away the global macro variables you find to then later on only delete the ones that didn't already exist at the beginning.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1688471187793.png" style="width: 294px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85547i383AC3729B0DE63E/image-dimensions/294x262?v=v2" width="294" height="262" role="button" title="Patrick_0-1688471187793.png" alt="Patrick_0-1688471187793.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 11:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883429#M349048</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-07-04T11:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883438#M349051</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How can I tell SAS-&lt;/P&gt;
&lt;P&gt;step 1-Recognize the macro vars that are user defined (It means that&amp;nbsp; user created them and they were not created automatically)&lt;/P&gt;
&lt;P&gt;step 2-Delete the macro vars from step 1&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you actually look at this MACRO_VARS data set with your own eyes? Did you try to detect a pattern or something in the data step that indicates which macro variables are ones you created and which are created by SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some things you can figure out yourself.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 12:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883438#M349051</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-04T12:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883442#M349053</link>
      <description>&lt;P&gt;SAS has published a way to do what&amp;nbsp; you ask:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0j1htu10wsx9tn1mig5g0b8mxxb.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0j1htu10wsx9tn1mig5g0b8mxxb.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 12:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883442#M349053</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-07-04T12:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883454#M349060</link>
      <description>&lt;P&gt;You could, as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;delete all macrovars with scope='GLOBAL'.&amp;nbsp; But in some contexts, it's likely a lot of those macrovars were not explicitly defined by the user, and deletion might be counterproductive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, every time you submit code in a SAS/Studio session, it defines a number of macrovars with global scope - for instance SASWORKLOCATION.&amp;nbsp; If that macrovar is deleted in the middle of the submitted code, you might run into a problem later in the submission.&amp;nbsp; Of course this is not a problem if the macrovar deletions only occur as separate code submissions, or at the end of multi-step submissions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative would be to use a naming convention for all your macrovar names, say starting all the macrovar names with double underscores (SAS will already have some with single underscores).&amp;nbsp; Then you could filter on&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;where scope='GLOBAL' and name EQT '__'&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;in the proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 14:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883454#M349060</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-07-04T14:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: delete macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883469#M349067</link>
      <description>&lt;P&gt;My understanding is both macro variable names that start with SYS and those that start with AF cannot be deleted.&amp;nbsp; Whether the macro variable was system-created or user-created is irrelevant.&amp;nbsp; A SAS developer decided that %SYMDEL can't delete those variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My practice is to delete global macro variables that don't start with SYS or AF, and for macro variables that do start with SYS or AF I set them to null.&amp;nbsp; My code is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.vmacro;
  where scope='GLOBAL' and offset=0 and name not like "SYS%" and name not like "AF%";  
  call execute('%nrstr(%%)symdel '||trim(left(name))||';');
run;

data _null_;
  set sashelp.vmacro;
  where scope='GLOBAL' and offset=0 and (name like "SYS%" or name like "AF%");  
  call execute('%nrstr(%%)let '||trim(left(name))||'=;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note both of these decisions may cause unwanted side effects.&amp;nbsp; For example, some clients like EG create a lot of global variables that may be used by the client, but do not start with SYS or AF.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 16:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-macro-variables/m-p/883469#M349067</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-07-04T16:40:31Z</dc:date>
    </item>
  </channel>
</rss>

