Setting Up SAS Studio

From sasCommunity
Jump to: navigation, search

SAS University Edition -- setting up SAS Studio for tool usage

Abstract

description
this page provides programs to discover how SAS Studio works and how to set up folders that contain programs for usage as %includes and autocall macros.
purpose
show programmers an example of how to use SAS Studio with reusable programs
audience
programmers

Folder Naming Conventions

The instructions for setting up SAS Studio folders provide suggested folder names.

  • main: SASUniversityEdition is suggested, this is a user choice
  • child: myfolders, this is specific, SAS-Studio will not run without this folder name

Folders

This is the folder structure used here.

Directory of C:\SAS-univ-edition
<DIR> myfolders
      <DIR> discovery
            <DIR> sas
            <DIR> sas7b
      <DIR> RnD
            <DIR> sas
            <DIR> sas7b
      <DIR> SAS-site
            <DIR> includes
            <DIR> macros


Files

List of Files

..\myfolders\autoexec-site.sas

..\myfolders\discovery\sas\echo-global-symbol-table.sas
..\myfolders\discovery\sas\echo-global-symbol-table.sas

..\myfolders\RnD\sas\autoexec.sas
..\myfolders\RnD\sas\demo-includes.sas
..\myfolders\RnD\sas\demo-macros.sas

..\myfolders\SAS-site\includes\put-global.sas
..\myfolders\SAS-site\macros\put_local.sas

autoexec-site

Notes:

  • this file is named autoexec-site so that SAS-Studio will not %include it
  • this file is %included by each project autoexec
  • the purpose is to standardize naming conventions of filerefs for all projects
  • todo: discover what "SASEnvironment/SASMacro" refers to
*C:\SAS-univ-edition\myfolders\autoexec-site.sas;
*usage in project autoexec;
*include "&userdir/autoexec-site.sas";
%put &=userdir;
filename site_inc  "&userdir/SAS-site/includes";
filename site_mac  "&userdir/SAS-site/macros";
options  mautosource sasautos=
(project site_mac "SASEnvironment/SASMacro" sasautos);

discovery echo-global-symbol-table

This file is used to echo the Global Symbol Table to the log.

The Global Symbol Table, as used here includes:

  • environment variables, set in configuration files or command-line
  • filerefs, allocated by filename statement
  • librefs, allocated by libname statement
  • macro variables, global, most commonly allocated by %let statement
  • options
*C:\SAS-univ-edition\myfolders\discovery\sas\echo-global-symbol-table.sas;
%put environment variables from configuration file(s);
%put %sysfunc(getoption(set));
%put %sysget(sasroot);
%put %sysget(sasautos);
 
%put autocall macro options: mautosource is boolean;
%put %sysfunc(getoption(mautosource));
%put autocall macro options: sasautos is filerefs;
%put %sysfunc(getoption(sasautos));
 
%put instantiate fileref sasautos, check fileref in option sasautos;
%include sasautos(af)/nosource2;
%put %sysfunc(getoption(sasautos));
 
%put global macro variables, SAS;
%put _automatic_;
%put global macro variables, SAS-Studio;
%put _global_;
*also put _user_;
 
%put filrefs: search paths for programs;
filename _all_ list;
%put librefs: search paths for data sets, catalogs;
libname  _all_ list;

Log

environment variables from configuration file(s)
[SASROOT = /opt/sasinside/SASHome/SASFoundation/9.4]
[SASAUTOS = ('!SASROOT/sasautos' )]

autocall macro options mautosource: boolean
62         %put %sysfunc(getoption(mautosource));
MAUTOSOURCE
63         %put autocall macro options sasautos: filerefs;
autocall macro options sasautos: filerefs
64         %put %sysfunc(getoption(sasautos));
( "SASEnvironment/SASMacro" '!SASROOT/sasautos' )

Notes:

  • In SAS the value of option sasautos is the single fileref sasautos.
  • The fileref sasautos has the list of folders in the environmental variable sasautos.
  • the first directory-specification is enclosed in double quotes, which usually indicates there are macro variables in the string
  • the second directory-specification is enclosed in single quotes, which is okay when referencing an environment variable (!SASROOT)
  • What is "SASEnvironment/SASMacro"???

SAS global macro variables

global macro variables, SAS
96         %put _automatic_;
...
AUTOMATIC SYSADDRBITS 64
...
AUTOMATIC SYSSCP LIN X64
AUTOMATIC SYSSCPL Linux
...
AUTOMATIC SYSVLONG4 9.04.01M2P-07-23-2014
AUTOMATIC SYSWARNINGTEXT Physical file does not exist,
                         /folders/myfolders/autoexec.sas.

SAS-Studio global macro variables

global macro variables, SAS-Studio
98         %put _global_;
...
GLOBAL USERDIR /folders/myfolders
...
GLOBAL _EXECENV SASProgrammer
GLOBAL _SASPROGRAMFILE foldersmyfoldersdiscoverysasechoglobalsymboltable.sas

Summary, Discovery

  • SAS-Studio is Linux
    • implication: Windows uses backward slash (\) in directory-specifications
    • Linux uses forward slash (/)
    • Linux is case-sensitive, all macro names must be in lower-case, as well as filenames containing definitions
  • SAS-Studio provide a global macro variable userdir which contains the root directory-specification for use in filerefs and librefs
  • SAS-Studio will execute an autoexec.sas file, if found in "&userdir"
  • macro variable _sasprogramfile contains special characters

discovery use-sas-program-file

This program shows how to deconstruct the macro variable sas-program-file.

*C:\SAS-univ-edition\myfolders\discovery\sas\use-sas-program-file.sas;
*name of program has special characters;
%put %unquote(&_sasprogramfile);
%let file_path = %unquote(&_sasprogramfile);
%put &=file_path;
%let file_name = %scan(&file_path,-2,./);
%put &=file_name;
%let file_name_log = %sysfunc(tranwrd(&file_path,.sas,.log));
%put &=file_name_log;
%let file_name_lst = %sysfunc(tranwrd(&file_path,.sas,.lst));
%put &=file_name_lst;


60   %put %unquote(&_sasprogramfile);
/folders/myfolders/discovery/sas/use-sas-program-file.sas
61   %let file_path = %unquote(&_sasprogramfile);
62   %put &=file_path;
FILE_PATH=/folders/myfolders/discovery/sas/use-sas-program-file.sas
63   %let file_name = %scan(&file_path,-2,./);
64   %put &=file_name;
FILE_NAME=use-sas-program-file
65   %let file_name_log = %sysfunc(tranwrd(&file_path,.sas,.log));
66   %put &=file_name_log;
FILE_NAME_LOG=/folders/myfolders/discovery/sas/use-sas-program-file.log
67   %let file_name_lst = %sysfunc(tranwrd(&file_path,.sas,.lst));
68   %put &=file_name_lst;
FILE_NAME_LST=/folders/myfolders/discovery/sas/use-sas-program-file.lst

project RnD autoexec

reminder: each project has folders: sas for programs and sas7b for data sets

This autoexec is for a project.

  • title for the project
  • provide a fileref project for project %includes
  • data sets and catalogs are in libref library
  •  %include the site autoexec to set access to site tools consistently
*C:\SAS-univ-edition\myfolders\RnD\sas\autoexec.sas;
title1 'SAS univ.ed RnD';
filename project "&userdir/RnD/sas";
libname  library "&userdir/RnD/sas7b";
%include         "&userdir/autoexec-site.sas";

project RnD demo-includes

Remember to submit the project autoexec, before submitting this program.

*C:\SAS-univ-edition\myfolders\RnD\sas\demo-includes.sas;
options source2;
%let libname = sashelp;
%let memname = class;
%let name    = age;
%let type    = n;
filename project list;
%include project(echo-global);
filename site_inc list;
%include site_inc(put-global);

log

64    filename project list;
NOTE: Fileref= PROJECT
      Physical Name= /folders/myfolders/RnD/sas
65    %include project(echo-global);
NOTE: %INCLUDE (level 1) file PROJECT(echo-global) is file
                     /folders/myfolders/RnD/sas/echo-global.sas.
66    +*C:\\SAS-univ-edition\\myfolders\\RnD\\sas\\echo-global.sas;
67    +%put &=libname &=memname &=name &=type;
LIBNAME=sashelp MEMNAME=class NAME=age TYPE=n
NOTE: %INCLUDE (level 1) ending.
68    filename site_inc list;
NOTE: Fileref= SITE_INC
      Physical Name= /folders/myfolders/SAS-site/includes
69    %include site_inc(put-global);
NOTE: %INCLUDE (level 1) file SITE_INC(put-global) is file
                      /folders/myfolders/SAS-site/includes/put-global.sas.
70    +*C:\\SAS-univ-edition\\myfolders\\SAS-site\\includes\\put-global.sas;
71    +%put &=libname &=memname &=name &=type;
LIBNAME=sashelp MEMNAME=class NAME=age TYPE=n
NOTE: %INCLUDE (level 1) ending.

project RnD demo-macros

options mautolocdisplay;
filename site_mac list;
%put_local()
options mprint;
%put_local(memname=shoes)

log

NOTE: Fileref= SITE_MAC
      Physical Name= /folders/myfolders/SAS-site/macros
60    %put_local()
MAUTOLOCDISPLAY(PUT_LOCAL):  This macro was compiled from the autocall file
          /folders/myfolders/SAS-site/macros/put_local.sas
PUT_LOCAL DATA &libname..&memname
PUT_LOCAL LIBNAME sashelp
PUT_LOCAL MEMNAME class
PUT_LOCAL NAME sex
PUT_LOCAL TESTING 0
note.1: data = &data contains special character ampersand
note.2: data = sashelp.class
note.3: DATA=sashelp.class resolved
TESTING=0 :: 0=false, 1=true
61        options mprint;
MAUTOLOCDISPLAY(PUT_LOCAL):  This macro was compiled from the autocall file
          /folders/myfolders/SAS-site/macros/put_local.sas
62        %put_local(memname=shoes)
PUT_LOCAL DATA &libname..&memname
PUT_LOCAL LIBNAME sashelp
PUT_LOCAL MEMNAME shoes
PUT_LOCAL NAME sex
PUT_LOCAL TESTING 0
note.1: data = &data contains special character ampersand
note.2: data = sashelp.shoes
note.3: DATA=sashelp.shoes resolved
TESTING=1 :: 0=false, 1=true
MPRINT(PUT_LOCAL):   proc sql;
MPRINT(PUT_LOCAL):   describe table sashelp.shoes;
NOTE: SQL table SASHELP.SHOES was created like:
create table SASHELP.SHOES( label='Fictitious Shoe Company Data' bufsize=65536 )
  (Region char(25),
   ...
   Returns num format=DOLLAR12. informat=DOLLAR12. label='Total Returns'
MPRINT(PUT_LOCAL):   quit;

SAS-site includes put-global.sas

*C:\SAS-univ-edition\myfolders\SAS-site\includes\put-global.sas;
%put &=libname &=memname &=name &=type;

SAS-site macros put_local.sas

%macro put_local
      (data    = &libname..&memname
      ,libname = sashelp
      ,memname = class
      ,name    = sex
      ,testing = 0);
%put _local_;
%let testing = %eval(not(0 eq &testing)
     or %sysfunc(getoption(mprint)) eq MPRINT);
%put note.1: data = %nrstr(&data) contains special character ampersand;
%put note.2: data = %unquote(&data);
%let data = &data;
%put note.3: &=data resolved;
%put &=testing :: 0=false, 1=true;
%if &testing %then %do;
    proc sql; describe table &data;
              quit;
    %end;
%mend;

Summary, Research and Development

SAS Studio

  • provides the ability to read an autoexec.sas file during startup
  • provides global macro variables userdir that can be used to allocate filerefs and librefs of programmers' tools, in %includes and macros
  • therefore, in the author's opinion, this is a good tool for programmers

References

--Ronald_J._Fehd macro.maven == thoretical programmer