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 SAS Studio

From sasCommunity
Revision as of 19:21, 4 August 2015 by Cameron (Talk | contribs)

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\echo-global-symbol-table.sas

..\myfolders\RnD\autoexec.sas

autoexec-site

Notes: this file is named autoexec-site so that SAS-Studio will not %include it.

*C:\SAS-univ-edition\myfolders\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.

*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_;
*name of program has special characters masked;
%put %unquote(&_sasprogramfile);
 
%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)

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

102        %put %unquote(&_sasprogramfile);
/folders/myfolders/discovery/sas/echo-global-symbol-table.sas 

Summary, Discovery

  • SAS-Studio is Linux
    • implication: Windows uses backward slash (\) in directory-specifications
    • Linux uses forward slash (/)
  • 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 does not contain special characters of directory-specifications, nor hyphens in filename

project RnD, autoexec.sas

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-include.sas

project RnD, demo-macro.sas

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
  • therefore, in the author's opinion, is a good tool for programmers


References


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