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

I have been using the following bit of code to delete the Global macro variables.

%macro delvars;
data vars;
set sashelp.vmacro;
run;
data _null_;
set vars;
if scope='GLOBAL' then call execute('%symdel '
||trim(left(name))||';');
run;
%mend;

 

Recently started getting the following two errors: (rest of the global macro variables seems to get deleted)

ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_ALL.

ERROR: Attempt to delete automatic macro variable SYS_SQL_IP_STMT.

 

I have no idea what these are. Any thoughts?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

If your naming convention for macro variables follows the recommendation of item 7 in Creating User-Defined Macro Variable Names -- "The prefixes AF, DMS, SQL, and SYS are not recommended ..." --, you can exclude those prefixes in your IF condition:

if scope='GLOBAL' & name ~in: ('AF' 'DMS' 'SQL' 'SYS') then ...

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Is there a reason you want to delete macro variables set by Proc SQL?

ballardw
Super User

One suspects that what you really are attempting to get to are the _USER_ defined variables, i.e. create by you, that are also Global in scope.

If that is the case then please say so.

madara155
Obsidian | Level 7

Hi

Yes, I just want to delete the global macro variables that I have defined. But I could not find another way to delete just the ones I defined.

Thanks.

FreelanceReinh
Jade | Level 19

If your naming convention for macro variables follows the recommendation of item 7 in Creating User-Defined Macro Variable Names -- "The prefixes AF, DMS, SQL, and SYS are not recommended ..." --, you can exclude those prefixes in your IF condition:

if scope='GLOBAL' & name ~in: ('AF' 'DMS' 'SQL' 'SYS') then ...
Quentin
Super User

Unfortunately, this is a hard task.  Many of the clients (EG, Studio, etc) litter the global symbol table with macro variables, which makes it difficult to know which are "yours".  

 

That said, there is a tech support note which says that macro variables starting with SYS and AF are reserved name spaces, so I delete everything but those:

 

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;

For the macro variables you can't delete, it is possible to set them to null:

 

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;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Astounding
PROC Star

Here's one more change I would recommend.

 

if scope='GLOBAL' and offset=0 and .....

Macro variables within sashelp.vmacro do not necessarily appear in just one observation.  They get stored in 200-character chunks.  So you may be trying to delete long macro variables twice.  Or more than twice.  Adding OFFSET=0 as a condition selects just one occurrence of the macro variable within sashelp.vmacro, and only attempts to delete the macro variable once.

madara155
Obsidian | Level 7
Thanks for your kind support! Appreciate it!

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 849 views
  • 2 likes
  • 7 in conversation