As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Dictionary.Libnames adding to FmtSearch

From sasCommunity
Jump to: navigation, search

Q: How can I add all librefs to FmtSearch so SAS can find all the format catalogs?

Harvested from SAS-L:

todo:

  • exclude the librefs already in FmtSearch: WORK LIBRARY are the defaults
  • this would be
  • Let FmtSearch = %sysfunc(getoption(FmtSearch));
  •  %sysfunc(tranwrd(FmtSearch,%str(" "),%str( )));*oops: arguments backwards!;
  • and add quotes to put in the Libname not in ("&FmtSearch."
  • Libname not in ("%sysfunc(tranwrd(%sysfunc(getoption(FmtSearch)),%str(" "),%str( )))"
  • options fmtsearch =(%sysfunc(getoption(FmtSearch)) &List.);
    • that won't work: value is (WORK LIBRARY) in parenthesis

Original Posting

* name: RnD-librefs;
PROC SQL; *select distinct memname from dictionary.dictionaries;
          *describe table dictionary.Libnames;
          *select * from dictionary.Libnames;
          select  Libname
            into  :List separated by ' '
            from  dictionary.Libnames
            where Libname not in ('SASHELP'
                                  'MAPS'
                                  'MAPSSAS'
                                  'MAPSGFK'
                                  'SASUSER'
                                  'WORK' 
                                  );
          quit;
%Put note: list of librefs: &List.;
options fmtsearch =(Work &List.);
%put note: FmtSearch: %sysfunc(getoption(FmtSearch));

log:

15         %Put note: list of librefs: &List.;
note: list of librefs: LIBRARY LIBSITE 
16         options fmtsearch =(&List.);
17         %put note: FmtSearch: %sysfunc(getoption(FmtSearch));
note: FmtSearch: (WORK LIBRARY LIBSITE)

Polished

libname Extra 'c:\temp\sas';
 
PROC SQL  noprint; 
          *describe table dictionary.options;
          *select * from  dictionary.options
          where OptName eq 'FMTSEARCH';
 
          select substr(Setting,2,length(Setting)-2)
          into  :List_FmtSearch
          from  dictionary.options
          where OptName eq 'FMTSEARCH';
 
          %Put note List_FmtSearch: &List_FmtSearch;
          %Let List_Dq = "%sysfunc(tranwrd
                        (&List_FmtSearch,%str( ),%str(" ")))";
          %Put note List_Dq: &List_Dq.;
 
          *describe table dictionary.Libnames;
          *select * from dictionary.Libnames;
 
          select  Libname
            into  :List_Librefs separated by ' '
            from  dictionary.Libnames
            where Libname not in ( &List_Dq
                                  'MAPS'
                                  'MAPSSAS'
                                  'MAPSGFK'
                                  'SASHELP'
                                  'SASUSER'
                                  );
          quit;
%Put note: list of librefs: &List_Librefs.;
 
options fmtsearch =( %cmpres(&List_FmtSearch &List_Librefs) );
%put note: FmtSearch: %sysfunc(getoption(FmtSearch));
 
%symdel List_Dq List_FmtSearch List_Librefs;

log:

[... Big Snip ...]
note List_FmtSearch: WORK LIBRARY
13                   %Let List_Dq = "%sysfunc(tranwrd
14                                 (&List_FmtSearch,%str( ),%str(" ")))";
15                   %Put note List_Dq: &List_Dq.;
note List_Dq: "WORK" "LIBRARY"

22                   select  Libname
23                     into  :List_Librefs separated by ' '
24                     from  dictionary.Libnames
25                     where Libname not in ( &List_Dq
[... Big Snip ...]
31                                           );
32                   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.09 seconds
[... Big Snip ...]
33         %Put note: list of librefs: &List_Librefs.;
note: list of librefs: EXTRA
34         
35         *options fmtsearch =(Work Library &List.);
36         options fmtsearch =( %cmpres(&List_FmtSearch &List_Librefs) );
37         %put note: FmtSearch: %sysfunc(getoption(FmtSearch));
note: FmtSearch: (WORK LIBRARY EXTRA)

--macro maven == the radical programmer 17:36, 14 May 2012 (EDT)