Monday, July 6, 2009

SAS: Create multiple datasets using a single Proc Means Procedure

e.g., we want to analyze data based on the following 3 combinations. Analysis Variable is fraud_amount. The 3 classification variables being
By fraud_type
By year and fraud_type
By year, month and fraud_type

Proc Means data=sales_data chartype;
Class year month fraud_type;
Var fraud_amount ;
Output out=fraud_type (where= (_type_='001') drop=year month) sum=; /*By fraud_type*/
Output out=year_fraud_type (where =(_type_='101' and year=2008) drop=month) sum=;
Output out=yr_month_fraud_type (where =(_type_='111')) sum=;
Run;

Chartype - converts the (default) numeric values of _TYPE_ to a character variable containing zeros and ones. The length of this variable is equal to the number of variables in the CLASS (or BY) statement.

_type_ - indicates which classification variables SAS should consider for analysis. i.e. _type_ = ‘1’ instructs SAS to consider the variable & ‘0’ instructs SAS to ignore the variable.


This way we do not have to have separate proc means for each classification, but we can combine them all in one step!!

No comments:

Post a Comment