Pages

SyntaxHighlighter

Friday, March 23, 2012

SAS Catalogs


SAS catalogs are heavily underutilized in my experience. Catalogs are analogous to a Zip file and are used to store formats, macros, SCL, graphics and more in catalog entries based on its type. Because catalogs are part of the SAS/BASE product, it is also a great way to store dynamically generated code then call it later on. Another benefit of using SAS catalogs to store information is that it is portable and does not have dependencies on OS storage devices that can change (e.g. does everyone have a c:\temp\ folder?).

A catalog is fully identified by a four-level name such as libref.catalog.entry-name.entry-type:

libref - the library that will store the catalog (use WORK for throw away entries)
catalog - name of the catalog (think of it as a zip file)
entry-name - name of the catalog entry
entry-type - types include SOURCE, LOG, OUTPUT, FORMAT, MACRO, CATAMS, SCL, GRSEG

The below code uses the disposable WORK libref to dynamically write out and then execute SOURCE code using both the full four-level name and the abbreviated version.

filename fullname catalog "work.catalog.mycode1.source" ;
filename abbrev   catalog "work.catalog" ;

data _null_   ;
  file fullname ;
  put "data _null_ ;"
    / "  put 'Hello from fullname' ;"
    / "run ;" ;
  file abbrev(mycode2.source) ;
  put "data _null_ ;"
    / "  put 'Hello from abbrev' ;"
    / "run ;" ;
run ;

%inc fullname ;
%inc abbrev( mycode2.source ) ;

filename fullname clear ;
filename abbrev clear ;

Reference: Using a SAS Catalog to Develop and Manage a SAS Project, by David D Chapman

Friday, March 2, 2012

Adding custom tips to GTL output

The default behavior for mouse over events is to show only the values being plotted. I contacted SAS tech support to find out how to display other variables in the output. The key is to use the rolename=(tip1=column) tip=(tip1) syntax shown below.

proc template ;
  define statgraph sgplot ;
    begingraph ;
      layout overlay ;
        ModelBand "G63LAMQ2" /  
          display=(outline) OutLineAttrs=GraphPredictionLimits 
          Name="MODELBAND" LegendLabel="95% Prediction Limits" ;
        ModelBand "G63LAMQ3" /  
          Name="MODELBAND1" LegendLabel="95% Confidence Limits" ;
        ScatterPlot X=Age Y=Weight / 
          primary=true 
          rolename=(tip1=name tip2=sex tip3=age tip4=weight) 
          tip=(tip1 tip2 tip3 tip4) ;
        RegressionPlot X=Age Y=Weight / 
          NAME="REG" LegendLabel="Regression" clm="G63LAMQ3" cli="G63LAMQ2" ;
        DiscreteLegend "MODELBAND" "MODELBAND1" "REG" ;
      endlayout ;
    endgraph ;
  end ;
run ;

ods graphics / imagemap = on ;
ods listing close ;
ods html path='c:\temp' file='tips.html' ;

  proc sgrender data=sashelp.class template=sgplot ;
  run ;

ods html close ;
ods listing ;