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

SAS Base Tips

SAS分为data step和proc step。data setp只要求以data开始,没有其他限制;而proc step则更像一个模板,每一个过程有确定可用的语句,用户根据需要往上面填写。Proc step几乎没有任何的技巧可言,Proc step应用的好坏一方面取决于你前面数据处理的好坏,另一方面取决于用户的统计基础,sas大多的技巧都集中在Data step。


Data step流程结构:每一种结构化语言编写的程序都由由顺序、选择、循环三种结构构成。

SAS语言在以下一些方面跟标准语言有比较大的差异:
·循环与自循环:Data step隐含了自循环的过程,这一SAS语言最具特色的机制在方便编程的同时也带来了理解上的麻烦;
·数据类型:只有两种类型,Character and numerical 识别和显示更多的数据形式依靠丰富的输入输出格式;
·数组:只用来存储变量,而不是具体的数据;
·函数:有着丰富的函数库,特别是统计相关的函数,但是没有提供自定义函数,实现这一功能的是宏;
·程序结构:任意一个SAS程序都是由Data step或proc步构成的,模块化的结构使程序看起来非常清晰。
SAS语言的这些特点使其更适合用来解决统计分析问题。

一、Data step的自循环(Data step's Built-in Loop):
1、Data step程序是一行一行的执行,这就意味着变量在使用之前必须创建。
2、Data step程序是一个观测一个观测读取。当程序正确的执行到Data step的最后一个语句时,就将该次读取的一条观测写入数据集,然后又重新开始执行Data step,继续读取观测值,这就是Data step的自循环。也就是相当于Data step的最后隐含包括了两个语句,output与return语句。

a.读取的数据在执行到最后写入数据集之前保存在哪里?
input语句执行后,SAS将读取的数据暂时先保存在内存缓冲区,然后执行后面的语句,后面的语句可以对暂存在内存缓冲区中的变量值进行修改,到最后才将整条数据写入数据集,写入数据集的数据就不能在当前Data step中再修改。

b.在Data step中间使用return语句会怎么样?自然是按照用户的意思进行执行,当遇到return语句时就重新执行Data step,读取下一条观测值,而跳过return后面的语句。

c.在Data step中间使用output语句呢?那么程序会在执行到output语句那里就把放在内存缓冲区里面的观测值写入数据集,而不是等到整个Data step执行完了再写入。

弄清楚这三个问题了应该弄明白Data step的自循环是怎么回事了。而且会发现原来Data step不一定是一次只可以读取一条观测,完全可以两条或者更多条一次的读取,比如重复input语句,并且在每条语句之后加一条output语句,就可以实现了。

二、数据类型(Data type):
SAS将各种各样的数据简化为两种类型,即数值型(numeric)和字符型 (character);
SAS的特别之处在于,两种基本的数据类型外加丰富的数据格式就能识别和显示各种各样的数据了,但是前提是你要告诉SAS怎么去识别和显示数据,按照什么格式去识别和显示数据,输入数据需要指明输入格式(informat),输出数据需要指明输出格式 (format)。

从数据类型角度我们把语言分为强类型的和弱类型,强类型的比方说C语言,在使用变量之前得先定义变量,而且必须指定一种数据类型。而SAS 则是弱类型的,也就是在用使用变量之前是不需要定义的,变量的类型取决于数据的类型或者预先定义的格式。
a. 字符常数(character)
如果带引号,则用不同引号引用,或将引号重复一次即可(用相同引号时)
b. 数值常数(numeric)
数值常数就是指在SAS语句中的数字,可以包含数字、小数点、符号和特殊记号E,如,1, -5, +49, 1.23, 01, 1.2E23, 0.5E-10等等
注意:若一个数值常数大于10E32-1,则必须表示成科学计数法。
c. 其它常数(data, time, and datetime)

''fmt
变量的类型转换(Type Conversions)
对于变量类型之间(字符型与数值型)的转换,取决于变量所在表达式的运算规则。
以上这些转换规则是SAS自动完成的,编程的时候最好是不要出现,因为虽然是自动完成,但是转换的结果不一定是我们预期的。

变量列表(variable list)
在SAS中,可以使用4种缩写的变量形式:
(1)数字系列:x1-xn;(2)变量名系列:x--a;(3)前缀名系列:item:。(4)特殊的变量列表:_ALL_,_CHARACTER_,_NUMERIC_。

三、数组

四、选择与循环
用于控制各计算操作执行的次序。
a.选择结构:if then else;select when otherwise end;
b.循环结构:do while end;do until end;步长型循环结构;特殊的循环结构;do over end(用于数组);
c.语句块:do end;
d.跳出:continue;leave;return;go to(一般少用,跳出多层循环);

五、sas视图界面
项目管理的功能,它可以将整个分析过程存储为项目文件供以后使用,包括数据集的路径、所执行的代码、相应的统计分析结果和统计图表等元素。有些功能目前只有在Analyst中提供而没有相对应的过程,如样本含量的估算和检验效能的计算等。
SAS网站上的支持服务中心

SAS Basics Programming

1. Output a dataset
Proc Print data=datasetName;
run;

2. define dataset
data dataset;
input x y @@;
datalines;
1 2 2 2
;
run;

3. Array
data arry;
   array r[8] r1-r8;
   do i=1 to 8;
        r[i] = i*8;
   end;
run;

proc print data= arry;
run;

4. 代码缩进: TAB , Shift+ TAB

5. define vars:
data datasetName;
input x1-x5;
input Sales_X    Sales_Y    Sales_Z;
datalines;
1 2 3;
run;

Proc print data=dataSetName;
var Sales: /* 用前缀 省略 */
run;

6. Sum 如何用?其他类似functions怎么用? 如何输入输出
data setme;
/* input some data: can define some logic and have some var list */
x1=9;
x2=39;
x3=sum(of x1-x2);

x1=5; x2=6; x3=4; x4=9;
y1=34; y2=12; y3=74; y4=39;
result=sum(of x1-x4, of y1-y4);
/* end define logic */
/* start input data */
input x6-x8 @@;
datalines;
2 3 4 3 4 5
;
run;

proc print data=setme;
var x3 result x6-x8; /* define a print list */
run;


7.  sum用法, _ALL_, _NUMERIC_, _CHARACTER_ 用法:指所有此类变量
                data sales1;
                /* define any data manipulation step before the input statement , for example */
                myvar = 1;
                myvar2 = myvar + 1;
                /* start of input statement */
input sales_a  sales_b book @@ ;
datalines;
1 2 3 3 2 3
;
run;

data xyz;
set sales1;
sum_sales =  sum (of sales:) ;
sum_all_numeric = sum (of _NUMERIC_) ; /* sum all numeric data */
run;

proc print data=xyz;
var sales: sum_sales sum_all_numeric  /* sum_numeric; */ ;
run;

8. SAS调试技巧 -- 代码截断问题诊断

Sort variable values within an observation: Smallest/Largest function

data one;
  input code1-code6;
datalines;
3 1 5 4 6 2
9 8 6 5 7 4
3 2 1 9 0 7
8 2 6 4 0 1
5 7 4 3 8 2
;

/* The DO UNTIL loop iterates until all of the variable values within an observation have          */
/* been sorted. Set SORTED to 1 and SORTED will be set to 0 each time the DO group executes        */
/* to reorder values. When that code does not execute, the array is already sorted, SORTED remains */
/* 1 and prevents the DO UNTIL loop from executing again.                                          */

data varsort(keep=code1-code6);
  array code(*) code1-code6;
  set one;
  do until (sorted);
    sorted=1;
    do i = 1 to dim(code)-1;
      if code(i) > code(i+1) then do;
        temp=code(i+1);
        code(i+1)=code(i);
        code(i)=temp;
        sorted=0;
      end;
    end;
  end;
run;

proc print data=varsort;
run;



/* Alternative method for SAS 9.0 and above using the SMALLEST function. */

/* The SMALLEST function returns the kth smallest non-missing value.     */ 
/* To reorder from largest to smallest, use the LARGEST value instead.   */

data two;
  keep reordered:;
  set one;
  array code(6);
  array reordered(6);
  do k=1 to 6;
    reordered(k)=smallest(k, of code1-code6);  
  end;
run;

SAS高级职位是什么样子的? (转载)

http://saslist.com/blog/category/%E5%88%86%E4%BA%AB/

A List of SAS Modules been installed

proc setinit noalias;
run;

---Base Product                                                            
---SAS/STAT                                                                
---SAS/GRAPH                                                               
---SAS/ETS                                                                 
---SAS/FSP                                                                 
---SAS/OR                                                                  
---SAS/AF                                                                  
---SAS/IML                                                                 
---SAS/QC                                                                  
---SAS/SHARE                                                               
---SAS/LAB                                                                 
---SAS/ASSIST                                                              
---SAS/CONNECT                                                             
---SAS/INSIGHT                                                             
---SAS/EIS                                                                 
---SAS/GIS                                                                 
---SAS/SHARE*NET                                                           
---MDDB Server common products                                             
---SAS Integration Technologies                                            
---SAS/Secure Windows                                                      
---SAS Bridge for ESRI                                                     
---OR OPT                                                                  
---OR PRS                                                                  
---OR IVS                                                                  
---OR LSO                                                                  
---SAS/ACCESS Interface to DB2                                             
---SAS/ACCESS Interface to ORACLE                                          
---SAS/ACCESS Interface to SYBASE                                          
---SAS/ACCESS Interface to PC Files                                        
---SAS/ACCESS Interface to ODBC                                            
---SAS/ACCESS Interface to OLE DB                                          
---SAS/ACCESS Interface to Teradata                                        
---SAS/ACCESS Interface to MYSQL                                           
---SAS Stat Studio                                                         
---SAS Workspace Server for Local Access                                   
---SAS/ACCESS Interface to Netezza                                         
---SAS/ACCESS Interface to NeoView                                         
---SAS/ACCESS Reserved Slot 555                                            
---SAS/ACCESS Reserved Slot 557                                            
---SAS/ACCESS Reserved Slot 560           

See the screen-shot for my installed SAS modules (On Win7 32 bit OS)                                 




The SAS 9.3 installation on win7 64bit

Expiration: .
Grace Period:  45 days (ending 28JUN2014).
Warning Period: 45 days (ending 12AUG2014).
System birthday:   23MAY2013.
Operating System:   WX64_WKS.
Product expiration dates:
---Base SAS Software

---SAS/STAT

---SAS/GRAPH

---SAS/ETS

---SAS/FSP

---SAS/OR

---SAS/AF

---SAS/IML

---SAS/QC

---SAS/SHARE

---SAS/LAB

---SAS/ASSIST

---SAS/CONNECT

---SAS/INSIGHT

---SAS/EIS

---SAS/SHARE*NET

---SAS Enterprise Miner

---SAS/IntrN

---MDDB Server common products

---SAS Integration Technologies

---SAS/Secure Windows

---SAS Text Miner

---SAS/Genetics

---SAS Enterprise Guide

---SAS Bridge for ESRI

---OR OPT

---OR PRS

---OR IVS

---OR LSO

---SAS/ACCESS Interface to DB2

---SAS/ACCESS Interface to Oracle

---SAS/ACCESS Interface to Sybase

---SAS/ACCESS Interface to PC Files

---SAS/ACCESS Interface to ODBC

---SAS/ACCESS Interface to OLE DB

---SAS/ACCESS Interface to Teradata

---SAS/ACCESS Interface to MySQL

---Text Miner for French

---Text Miner for German

---SAS/IML Studio

---SAS Workspace Server for Local Access

---SAS/ACCESS Interface to Netezza

---SAS/ACCESS Interface to Aster nCluster

---SAS/ACCESS Interface to Greenplum

---SAS/ACCESS Interface to Sybase IQ

---DataFlux Trans DB Driver

---SAS Framework Data Server

---Reserved for Dataflux

---SAS Add-in for Microsoft Excel

Wednesday, March 19, 2014

SAS 9.2 Resource

SAS 9.2 多国语言版 SID and Crack:
https://drive.google.com/file/d/0B1HAtnBFz1rwM0tPQUNOM1RKQVU/edit?usp=sharing

SAS 9.2 Installer:
https://drive.google.com/file/d/0B1HAtnBFz1rwREFzM3JiNC1OemM/edit?usp=sharing

Monday, March 10, 2014

The next step on SAS move

1. read SAS on clinical trial, papers
2. find the code, change and modified the code, add macro
3. research on the statistic models
4. make some audio, if necceray, include SAS, DA, SAP and some communication, writing things

SAS Data analysis training - China


SAS ETL
SAS C#
SAS Report

http://www.dataguru.cn/article-1417-1.html
第1周 SAS体系介绍:逻辑库,变量、函数、操作符与SAS表达式,数据步基本语句
第2周 ETL技术之一:复杂的数据步控制,读取外部文件和数据库连接
第3周 ETL技术之二:数据集整理。跳转、循环、数组等,数据集合并,OUTPUT语句
第4周 ETL技术之三:过程步常用语句,几个常用过程,SQL过程
第5周 初识SAS分析之一:描述性统计量计算过程
第6周 初识SAS分析之二:制表与画图
第7周 真理还是谬误?拉出来遛遛:假设检验
第8周 告别拍脑袋式的肉眼判断:方差分析
第9周 我也是个预言家之一:相关分析与线性回归模型
第10周 我也是个预言家之二:Logistic回归模型与非线性回归
第11周 人生大部分问题是抉择问题:分类器
第12周 人以群分,物以类聚:聚类分析
第13周 抓住背后看不见那只手:主成分分析与因子分析
第14周 不是算命先生:生存分析,COX回归模型
第15周 股神是怎样炼成的:时间序列与ARIMA模型


Some shared SAS files:
SAS 9.2:  I tested on win7, success installed
SAS 9.2  multi-language crack, with SID.

https://drive.google.com/file/d/0B1HAtnBFz1rwM0tPQUNOM1RKQVU/edit?usp=sharing
https://drive.google.com/file/d/0B1HAtnBFz1rwREFzM3JiNC1OemM/edit?usp=sharing