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

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

Autoexec Companion

From sasCommunity
Jump to: navigation, search

MWSUG.2015 An Autoexec Companion, allocating location names during Startup

For more information on the SAS autoexec file, see this page.

title1   'An Companion';
         %let %sysfunc(getoption(sysin,keyword));
         %put echo &=sysin;
title2   "&sysin";               *** path\;
title2   "%scan(&sysin,-2,/\.)"; *** program-name only;
         *** allocate environment variables;
               *** relative: sibling folder;
options  set = out_pdf   "..\out-pdf";    *   double quotes;
options  set = out_rtf   '..\out-rtf';    *or single quotes;
               *** absolute: hard-coded   compare to site_lib;
options  set = site_root 'C:\SAS-projects\SAS-site';
         *** various folders with input files;
filename in_csv  '..\csv';
filename in_dat  '..\dat';
filename project '.';* here: startup folder: *.sas programs;
         *** use bang (!) as prefix to reference an e-var;
filename site_inc "!site_root\includes";  *   double quotes;
filename site_mac '!site_root\macros'  ;  *or single quotes;
libname  library  '..\sas7b';               *sibling folder;
*libname  site_lib '!site_root\sas7b';
libname  site_lib '..\..\SAS-site\sas7b';*compare to site_root;
         *** functions compiled by proc fcmp in data set;
options  cmplib = library.functions;*or site_lib.functions;
         *** format catalogs, see also option fmterr;
options  fmtsearch = (work library site_lib.formats);
** pair  macro autocall: boolean, search-path filerefs;
options  mautosource
         sasautos = (project site_mac sasautos);
** pair  macros compiled and stored: boolean, one libref;
options  mstored  sasmstore = library;      *or site_lib;
options  nofmterr         %* no err msg: fmt missing;
         fullstimer       %* max info in timer block;
         msglevel = i     %* more messages in log   ;
options  nocenter         %* flush left output      ;
         nodate           %* no date-stamp          ;
         nonumber         %* no pages numbers       ;
         details          %* proc contents          ;
         formchar =       %* no special chars       ;
         formdlim = ' '   %* no CR/LF for page break;
         linesize = max   %* for LaTeX printing     ;
         pagesize = max;  %* no page breaks in *.lst;



sas autoexec-test -echoauto

**** name:;
**** many options are set in configuration files;
%put echo sascfg=%sysget(sascfg);
%put echo %sysfunc(getoption(config,keyword));
*command-line option sasinitialfolder may be set by icons;
*or project config, compare to folder of fileref project;
%put echo %sysfunc(getoption(sasinitialfolder,keyword));
*review all filerefs;
filename _all_ list;
**** review of functions;
%let %sysfunc(getoption(cmplib,keyword));
            ,%nrstr(%put echo exist(&cmplib);)
        ,%nrstr(%put echo not exist(&cmplib);),))
%let exist_catalog = %nrstr(echo
      ,,%nrstr(not ),))exist &catalog);
**** formats: search list of librefs;
%let %sysfunc(getoption(fmtsearch,keyword));*remove parens;
%let fmtsearch=%substr(&fmtsearch,2,%length(&fmtsearch)-2);
%put echo &=fmtsearch;
**** check default = work library;
%let catalog = work.formats;
%put %unquote(&exist_catalog);
%let catalog = library.formats;
%put %unquote(&exist_catalog);
**** remove default librefs WORK and LIBRARY;
%let fmtsearch=%sysfunc(tranwrd(&fmtsearch,WORK,%str( )));
%let fmtsearch=%sysfunc(tranwrd(&fmtsearch,LIBRARY,%str( )));
**** there may be one, or more;
%let fmt_lib = %scan(&fmtsearch,1,%str( ));
**** if fmt-lib has dot then is two-level name;
%let catalog = %sysfunc(ifc(%index(&fmt_lib,.)
     ,%nrstr(&fmt_lib),%nrstr(&fmt_lib..formats) ));
%put %unquote(&exist_catalog);
**** macro autocall;
%put echo mautosource=%sysfunc(getoption(mautosource));
%put echo %sysfunc(getoption(sasautos,keyword));
*allocate fileref sasautos to check if modified in config;
%include sasautos(af)/nosource2;
%put echo sasroot=%sysget(sasroot);
filename sasautos list;
**** if  sasautos contains paths other than sasroot
     then review configuration file(s) listed above;
**** macros compiled and stored;
%let mstored  =%sysfunc(getoption(mstored));
%let sasmstore=%sysfunc(ifc(&mstored eq MSTORED
%put echo &=mstored &=sasmstore;
%let catalog = &sasmstore..sasmacr;
%put %unquote(&exist_catalog);


--Ronald_J._Fehd macro.maven == the radical programmer (talk) 08:07, 7 October 2015 (CDT)