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

I have a sas macro catalog named test. This catalog contains list of macros (stored as catalogs). I want to remove specific catalogs from test. Is there a way to do in SAS?

For example  test contains A,B,C ,V_A,V_B,V_C.I want to keep only A,B,C.

Appreciate your response.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

You can build the list of macros to delete using PROC SQL and the SASHELP.VCATALG list, then use that list in PROC CATALOG.

 

Let's assume your macros are in a catalog named MYMACROS within the library MYLIB, and you want to catch the "V_*" named macros:

 

proc sql noprint;
 select objname into: vmacs separated by ' ' from sashelp.vcatalg
 where substr(objname,1,2) = "V_" and libname='MYLIB' and memname='MYMACROS'
and objtype='MACRO';
quit;

/* space-delimited list of matching macro names */
%put &=vmacs;

proc catalog
  cat=MYLIB.MYMACROS entrytype=macro;
  delete &vmacs.;
run;
quit;
 

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

You can accomplish this with PROC CATALOG. Do you have SAS Enterprise Guide? The Catalog and Formats Explorer (in the Tools menu) can help generate this code for you.

 

ChrisHemedinger_0-1729786799487.png

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
sri1
Obsidian | Level 7

Thanks for your response,am using sas 9.4

Tom
Super User Tom
Super User

@sri1 wrote:

I have a sas macro catalog named test. This catalog contains list of macros (stored as catalogs). I want to remove specific catalogs from test. Is there a way to do in SAS?

For example  test contains A,B,C ,V_A,V_B,V_C.I want to keep only A,B,C.

Appreciate your response.


Your terminology is messed up.  The catalog cannot contain other catalogs. A "macro catalog" usually means a SAS catalog file that contains compiled macros.  The object (or entry) type for a compiled macro is 'MACRO'.  The object name is the macro's name.

 

You can use PROC CATALOG to manage catalog entries.  Use the SAVE command if you want to delete all but the listed entries.  So if your catalog name is MYLIB.MYMACROS then the code would look like:

proc catalog cat=MYLIB.MYMACROS entrytype=macro;
  save a b c ;
run;

 

sri1
Obsidian | Level 7

Thanks for your response. There are numerous macros with prefix V_ , is there a way I can delete all the macros with prefix V_

ChrisHemedinger
Community Manager

You can build the list of macros to delete using PROC SQL and the SASHELP.VCATALG list, then use that list in PROC CATALOG.

 

Let's assume your macros are in a catalog named MYMACROS within the library MYLIB, and you want to catch the "V_*" named macros:

 

proc sql noprint;
 select objname into: vmacs separated by ' ' from sashelp.vcatalg
 where substr(objname,1,2) = "V_" and libname='MYLIB' and memname='MYMACROS'
and objtype='MACRO';
quit;

/* space-delimited list of matching macro names */
%put &=vmacs;

proc catalog
  cat=MYLIB.MYMACROS entrytype=macro;
  delete &vmacs.;
run;
quit;
 

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 6 replies
  • 1105 views
  • 5 likes
  • 3 in conversation