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.
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;
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.
Thanks for your response,am using sas 9.4
@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;
Thanks for your response. There are numerous macros with prefix V_ , is there a way I can delete all the macros with prefix V_
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;
Appreciate your response, thanks
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.