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.


Setting Up Project Config and AutoExec

From sasCommunity
Jump to: navigation, search

Setting Up Project Config and AutoExec

TinyUrl: http://tinyurl.com/27oaapt

http://www.sascommunity.org/wiki/Setting_Up_Project_Config_and_AutoExec

This article examines the issues of moving hard-coded global statements from many programs into a project autoexec.

Global Statements

These global statements are candidates for inclusion in a project autoexec.

  • Titles and Footnotes
  • FileNames
  • Libnames
  • Options

Titles and Footnotes

Placement on page

Choice: centering or flush left

options   center; *default;
options nocenter; *flush left;

See also: options linesize, pagesize, orientation.

Pagination

options noDate     %* no date-stamp  ;
          DtReset  %* date+time reset;
        noNumber   %* no page numbers;
        ;

Tip: use the macro function sysfunc to place a date-stamp in other than title1. Experiment with other datetime formats. Note the default is time + weekdate.

%Put %sysfunc(datetime(),datetime21.2));
Title2 "%sysfunc(datetime(),datetime21.2))";
Title3 "%sysfunc(time(),timeampm11.) "
       "%sysfunc(date(),weekdate37.)";
run;

See Fehd's macro TextLine to justify (left, center, right) text in titles or footnotes:

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0212B&L=sas-l&P=R16544

Specifying more than one Directory-Specification

Note: both the filename and libname statements use the following syntax for specifying a list of directory-specifications, which must be enclosed in parenthesis.

         *single;
filename Folder1  'c:\temp\sas';
         *list:    enclose in parenthesis;
filename Folders ('c:\temp1'
                  'c:\temp1');

FileNames

The filename statement is used to provide symbolic names of folders, which sas documentation refers to as directory-specification.

Common assignments:

Filename Project  '.';*here: see option SASinitialFolder;
Filename SiteIncl 'C:\SAS\site\includes';

Filerefs are used by option sasautos.

LibNames

Common assignments:

Libname  Library  '..\sas7b';
Libname  LibWork  (Work)    ;

Librefs are used by options CmpLib and SASmStore.


Options

Any option used anywhere is a candidate for assignment in the autoexec.

options MsgLevel = I; * extra messages displayed; 


Folder Naming Conventions

Site

Directory of C:\SAS\site

11/18/2005  01:01p  <DIR>  formats
11/18/2005  02:02p  <DIR>  functions
11/18/2007  03:03p  <DIR>  includes
11/18/2005  05:05p  <DIR>  MacroCatalog
11/18/2007  08:08p  <DIR>  macros
11/18/2007  13:13p  <DIR>  MacrosCompileAndStore
  • formats: contains catalog: formats.sas7bcat
  • functions: contains SAS data sets with functions compiled by proc fcmp
    • Note: 9.2
  • includes: contains utility programs
  • MacroCatalog: contains catalog: sasmacro.sas7bcat
  • macros: autocall: contains programs with macros
  • MacrosCompileAndStore: contains programs with macros to store

Project

Directory of C:\SAS\projects\SetUpProject

11/18/2007  03:52p  <DIR>  sas
11/18/2005  03:51p  <DIR>  sas7b
11/18/2007  01:32p  <DIR>  sas7bWork
  • sas: contains program text files
  • sas7b: contains SAS-created files:
    • catalogs: *.sas7bcat,
    • data sets: *.sas7bdat,
      • etc.
  • sas7bWork: contains temporary data sets; used while testing;

Environmental Variable SASsite

Configuration file

In either of

  • SASv8.cfg
  • SASv9.cfg

you can allocate an environment variable using configuration file syntax

-set SASsite 'C:\SAS\Site'

autoexec

This environmental variable can be also allocated in the autoexec with this statement:

options set = SASsite 'C:\SAS\Site';

autoexec.sas examples

autoexec.sas accessing only project folders

*autoexec.sas;

Title1  'Fehd: Setup Project config and autoexec';
*Footnote1 '?';

options  noCenter    %* flush left output;
         noDate      %* no date-stamp    ;
           DtReset   %* date+time reset  ;
         noNumber    %* no page numbers  ;
         ;

Filename Project  '.';
Libname  Library  '..\sas7b';
Libname  LibWork  (Work)    ;

options  CmpLib = Library.functions;* data set;

* macros: autocall: *.sas;
options  MautoSource 
         SASautos = (Project 'C:\SAS-site\macros' SASautos);

* macros: compiled and stored in catalog: SASmacr.sas7bcat;
options  Mstored SASmStore = Library;

options                  %*miscellaneous;
         details         %* Proc Contents           ;
         FormChar =      %* no special chars        ;
                         '-------------------'
         FormDlim = ' '  %* no CR/LF for page break ;
         LineSize = max  %* no squeeze output       ;
         MsgLevel = I    %* extra messages displayed;
         PageSize = max  %* no page breaks in *.lst ;
         ;

autoexec.sas for a project accessing site folders

Q: Can we access both autocall and compiled macros?

A: Yes.

  • Autocall: the compiled code from autocall macros is stored in Work.sasmacr.catalog.
  • Compiled and stored macros: The macro statement of compiled macros contains the directive store, which directs their compiled code to storage in Libref.sasmacr.catalog.

The files containing these macro definitions are not in the same folders as autocall macros, therefore you would not autocall a macro with a store directive in its definition.

Summary: There are two different folders containing files which are either autocall or compiled and stored macros. You would not put the folder containing macro definitions with the store directive in the autocall folder list.

*autoexec.sas;

Title1  'Fehd: Setup Project config and autoexec';
*Footnote1 '?';

options  noCenter    %* flush left output;
         noDate      %* no date-stamp    ;
           DtReset   %* datetime reset   ;
         noNumber    %* no page numbers  ;
         ;

Filename Project     '.';
Filename SiteIncl    '!SASsite\includes';

Libname  Library     '..\sas7b';
Libname  LibWork     (Work)    ;

Libname  SiteFmts    '!SASsite\formats';
options  FmtSearch = (Work Library SiteFmts);

Libname  SiteFunc    '!SASsite\functions';
options  CmpLib    = (Library.functions
                      SiteFunc.functions);

options  MautoSource  %* macros: autocall: *.sas;
         SASautos  = (Project  '!SASsite\macros'
                      SASautos);

                      %* macros: stored: SiteMacr.SASmacr.sas7bcat;
Libname  SiteMacr    '!SASsite\MacroCatalog';
options  Mstored
         SASmStore = (Library SiteMacr);

options                   %* miscellaneous;
         details          %* Proc Contents           ;
         FormChar  =      %* no special chars        ;
                          '-------------------'
         FormDlim  = ' '  %* no CR/LF for page break ;
         LineSize  = max  %* no squeeze output       ;
         MsgLevel  = I    %* extra messages displayed;
         PageSize  = max  %* no page breaks in *.lst ;
         ;


See also:

Deallocating Libref of Compiled and Stored Macro Catalog

  • From: D. Henderson
  • Sent: Friday, January 16, 2009 1:31 PM
  • To: SAS-L
  • Subject: RE: De-allocating libref of stored macro catalog

A trick I have used with some success is to reassign the sasmstore option to another lib and compile a dummy macro. Once I do that, the original libref can be cleared.

* UnTested! -- RJF2;
                      * macros: stored: SASmacr.sas7bcat;
Libname  SiteMacr    '!SASsite\MacroCatalog';
options  Mstored
         SASmStore = (Library SiteMacr);
*...;
options  SASmStore = DummyLib;
%Macro NoOp/ store;
%mend;
run;
libname Library  clear;
libname SiteMacr clear;
run;

References

--macro maven == the radical programmer 16:07, 28 November 2007 (EST)