SAS

As a statistical package SAS has few equals. It has a rich set of statistical procedures and excels at data manipulation. The examples below are for Base SAS. The EDI is ok and there is a learning version available. BASE SAS is a procedural scripting language.

Tip1

Proc SQL SAS allows you to code using both their internal proprietary data manipulation method, data steps and SQL.

Tip2

Dictionary

proc sql noprint NoErrorStop;
create table TmpVarNames as
(select OldCol.name
from dictionary.Columns as OldCol
where oldcol.libname = upper( Work )
and OldCol.memname =  upper( tmpBase )
and upper(OldCol.name) ne  upper( &DependVarible. )
and OldCol.type ne  char
and OldCol.format not in  ( DATETIME.       ) )
order by  OldCol.name ;
Tip3

Macro Variables

Variables that can be used through out your script. %let &MyMacroVar = Test;
&MyMacroVar.;
Tip4

Build Dynamic Commands

proc sql noprint NoErrorStop;
select %quote(%)AddWieghts( || name || ,
&WeightVariable. , tmpBase )   Into :RunTest0 separated by ;

from  TmpVarNames;
quit;
&RunTest0.;

Tip5

Macros You can create functions or macros of operations  often repeated in your code.

%macro MyMacro();
%Put ‘Hello’;
%end;
%MyMacro;
%MyMacro;
%MyMacro;
%MyMacro;
Tip6

Options There are a number of system options you can control in your code.

Option obs = 100;

Sets the max observation for all datasets to 100;

Tip7 SasAutos One of the most useful options is to set  the path for a common macro library.  Now when searching for macros called within you script SAS will include this path.

Options SasAutos = ( c:\StatMacros\ ) ;
Tip8

View Macros in Memory

proc sql noprint;
select %let ||compress(name)|| =
into : resetmv separated by ;
from dictionary.macros
where scope= GLOBAL ;
quit;
Tip9

ODS ODS allows you to out put all results as HTML.

ods html;
<<My code here>>
odo html close;
Tip10

Display a Message

%window start
#5  @28  &TxtMessage ;
%display start;
Tip11

Find Error

%if &syserr > 4 %then %do;
%end;
Tip12

Halt Code The code below puts a %macro into the code stream therefore ignoring all subsequent code until %mend is typed in.

%if &syserr > 4 %then %do;
%unquote(%nrstr(%macro noexecdummy;));
%end;

Leave a Reply

Your email address will not be published. Required fields are marked *