Monday, March 31, 2014

SAS/SCL and SAS/AF --- SAS Class & UI

  • Using SCL to create a class and to define: attributes,methods,events and event handlers 
  • Using the CLASS block provides the advantages of error detection at compile time and improved performance during run time. 
  • You can also overload method definitions, which means that multiple methods can have the same name, but have different numbers and types of parameters.
  • 1991, SAS/AF --- Software applications of any sort do not exist in isolation; they are built with a specific need in mind.
  • Screen Control Language (SCL,renamed SAS Component Language for Version 7)

For more details:
http://www2.sas.com/proceedings/sugi24/Begtutor/p69-24.pdf
http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_913/af_gsframes_9346.pdf
To create a class from an SCL entry that contains a CLASS block, you must compile and save the SCL entry as a CLASS entry. To do this, either issue the SAVECLASS command or select File [arrow] Save Class from the SCL Source Editor. This is equivalent to using the Class Editor to interactively create a CLASS entry. However, the Class Editor provides a graphical view of the class, whereas the CLASS statement in SCL provides a language view of the class.
Do not declare the _SELF_, _FRAME_, _CFRAME_, _METHOD_, or _EVENT_ system variables inside a CLASS or USECLASS block. SCL automatically sets these values when it is running methods that are defined in CLASS or USECLASS blocks. Redefining any of these system variables can introduce unexpected behavior.
In methods that are defined in a CLASS statement block, all references to the methods and the attributes of the class can bypass two-level references to _SELF_.attribute and _SELF_.method(...). Because these methods are defined within the class, the SCL compiler can detect whether an undefined variable is a local variable or a class attribute.
You can also use the _super method in method code inside a CLASS statement block without having to specify either an object identifier or the method whose super method you are calling. You can use the _super method to call any method. For example, to invoke the super ADD method, you would use

Saturday, March 29, 2014

SAS 9.2 Install Notes

1.使用虚拟光驱:ULtroISO, 加载SAS第一张盘
2. 运行安装文件
3. 修改系统时间
4. 选择安装的SID文件

    此压缩包包含除SAS安装包以外的其他全部资料,也就是说你还需要下载SAS9.2安装程序。
    破解过程非常简单:
1、将系统时间修改到你所拥有的SAS9.2 SID文件有效期之前,比如这个压缩包里附带的SID文件([SAS.9.2多国语言版].SAS92_343247_70009309_Win_Wrkstn)有效期至2009/06/03,你将系统时间改为2009/06/03之前的任意一天即可。
2、安装你所下载的SAS9.2,可以顺利安装到电脑上。
3、运行SYDAY软件,打开后可以先点最右边的头像观看使用教程,进行设置。
4、将系统时间改回。

Friday, March 28, 2014

Informat

/* informat
Character Informats: $INFORMATw. --> $10.
Numeric Informats: INFORMATw.d --> 4.5
Date/Time Informats: INFORMATw --> mmyydd9.
*/


Example:

outStr = cats("cols=", PUT(&cols, $10.));
put outStr;

How to debug SAS code using Data Step Debuger

Debug Command:
data xxx / debug
go -- until break 7
step = return
examine _all_
quit
set
                break point:

/*  =----------- debug examples -------
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000379345.htm
*/

/* debug example: first execution */
data tours (drop=type) ; * / debug;
retain Tour; /* add retain to keep the data */
input @1 type $ @;
    if type='H' then
      do;
     input @3 Tour $20.;
     return;
      end;
   else if type='P' then
 do;
     input @3 Name $10. Age 2. +1 Sex $1.;
     output;
      end;
   datalines;
H Tour 101
P Mary E    21 F
P George S  45 M
P Susan K    3 F
H Tour 102
P Adelle S  79 M
P Walter P  55 M
P Fran I    63 F
;
run;
proc print data=tours;
   title 'Tour List';
run;



/*  =----------- debug example 2 -------*/
options yearcutoff=1920;

data tours / debug;
  length Country $ 10;
  input Country $10. Start : mmddyy. End : mmddyy.;
  Duration=end-start;
datalines;
Italy       033000 041300
Brazil      021900 022800
Japan       052200 061500
Venezuela   110300 11800
Australia   122100 011501
;

proc print data=tours;
   format start end date9.;
   title 'Tour Duration';
run;


/* in debug: show output, then
1. break lineNo when country="Venezuela" --- break at error point
2. examine the date var: examine start date7.  | examine start mmddyy.
3. set start='18Nov00'd

Debugger Commands:
http://www.sfu.ca/sasdoc/sashtml/lgref/z0379386.htm
-------------
BREAK lineNo ; breake 4 when strVar=''; break 4 when numVar=value; 
break 4 after numberOf_Loop
JUMP lineNo
DELETE break lineNo
SET var=Value, when debug, can set some value for debug purpose
ENTER = step
STEP  = excute a statement, step forward
EXAMINE varName, _ALL_
GO lineNo.
QUIT

CALCULATE expression
LIST
DESCRIBE
SWAP
TRACE
HELP
WATCH
*/


/*  =----------- debug example 3 -------*/
/* break 331 after 5(loop repeat counts) */
data old;
input oldtest @@;
datalines;
2 3 3 4 4 4 5 5
;
run;


data new / debug;
   set old;
   do i=1 to 20;
      newtest=oldtest+i;
      output;
   end;
run;

Macro tips

/* --------------- Macro 1---Input Number------------- */
%let inputRows = 8;
%let inputCols = 6;

%macro getInput(rows, cols);
data _null_;
if &rows > &cols then
do;
outStr = cats("rows=", PUT(&rows, $10.)); /* format + &var */
put outStr;
  end;
else
do;
outStr = cats("cols=", PUT(&cols, $10.));
put outStr;
end;
%mend;
%getInput(&inputRows, &inputCols);


/* ------------ Macro 2: input dataset ------------- */
/* user parameter to replace a dataset in macro */
%macro getDataset(dataset);
data _null_;
set &dataset;
if x>=y then put x=;
else put y=;
%mend;

data inputDataSet;
 input x y;
 cards;
 7 3
;
run;
%getDataset(inputDataSet);


/* ----- Macro 3---Input numeric and character and date ------------- */
%let sheetTitle = "The excel sheet title";
%let sheetID = 1;

%macro getNumCharParam(sheetTitle, sheetID);
data _null_;
if &sheetID > 2 then
do;
outStr = cats("sheet title is=", &sheetTitle); /* format + &var */
put outStr;
  end;
else
do;
outStr = cats("sheet title is=", "get nothing as id < 2");
put outStr;
end;
%mend;

%getNumCharParam(&sheetTitle, &sheetID);

/* --------  Macro 4: to return a value in dataset */
%macro macroReturnValue(inputVar, returnDataset);
data &returnDataset;
retValue = 0;
%do i=1 %to &inputVar;
retValue = retValue + 1 ;
%end;
%put retValue;
run;
%mend;

%let reapeatTimes = 1000;
%let datasetName = returnedDataSet;
%macroReturnValue(&reapeatTimes, &datasetName);
proc print data= &datasetName;
var retValue;
run;

/* Simple Macro call */
%macro xl2sas(row, col);
%put &row;
%put &col;
%mend xl2sas;
%xl2sas(3,4);

macro variables are used to store and manipulate character strings and  not the same as the DATA step variables and are stored in memory in a macro symbol table

Library references are created in order for SAS to read or write a SAS data set to a directory (or
folder). SAS calls the directory or folder a library and assigns “nicknames” to these libraries.

2. SAS® Macro Dynamics - From Simple Basics to Powerful Invocations
http://www2.sas.com/proceedings/sugi31/039-31.pdf

Thursday, March 27, 2014

How to leverage user-defined SAS functions

Target:
Use function for input-output programming:
1.  input(varString $, varNum)  lengthOfReturnedString $;
2.  input(varNum, varNum,...) lengthOfReturnedNum ;
3.  input(varString $ , varString $, ...)  lengthOfReturnedString $;

Solution:
1.
proc fcmp outlib=sasuser.funcs.test;
function inOut(number, str $)  $ 500;
if number > 5 then
strOut = cats(str, "the input greater than 5");
else
strOut = cats(str, "the input less than 5");
return(strOut);
endsub;

options cmplib=sasuser.funcs;
data _null_;
number = 50;
str = "Here is the result: ";
strOut = inOut(number, str);
put strOut= ;
run;

2.

proc fcmp outlib=sasuser.funcs.trial;
function sum_two_input_values(in1, in2);
n = in1 + in2;
return(n);
endsub;

data _null_;
in1 = 2;
in2 = 3;
nm = sum_two_input_values(in1, in2);
put nm=;
run;


3.

/* function 2: string = conStr(string1, string2) */
proc fcmp outlib=sasuser.funcs.trial;
* input is character, output is character with length;
function conStr(str1 $ , str2 $) $ 20;
length str1 $ 10 str2 $ 10 outStr $ 20;
outStr = cats(str1, str2);
return(outStr);
endsub;
run;
options cmplib=sasuser.funcs;
data _null_;
in1 = 'd2';
in2 = 'k3';
kk = conStr(in1, in2);
put kk=;
run;

More information:
http://support.sas.com/resources/papers/proceedings11/083-2011.pdf

Saturday, March 22, 2014

Data Analyst Job Titles

Analyst, Management Decision Support (MDS)
BI Report Developer
clinical trial anylyst
Data Analyst
Data Coordinator
Data Engineering Analyst
Data Quality Analyst
Data Scientist
Data Scientist
Database Programmer
ETL Consultant
Health Analyst
Informatics Developer
Information Analyst
Intelligence Developer

PREDICTIVE DATA MODELLER
Programmer Analyst
Sales Analyst
SAS Analyst
SAS Application Developer
SAS BI Support
SAS Business Analyst
SAS Developer
SAS Modeler
SAS Modeling
SAS Programmer
Senior Analyst - Decision Support
Software Developer and Application Tester
Statistical Programmers
Technical Analyst