Place to learn SAS and enhance your professional career...
Jan 11, 2013
Simple SAS Macro to analyze a SAS dataset...
Data analysis is a process of inspecting, cleaning, transforming, and modelling data with the goal of highlighting useful information, suggesting conclusions, and supporting decision making.
The first step in this process is to know about your data… - Know what kind of data are you dealing with i.e. financial, pharmaceutical etc. - If you have access to the data..quickly run a freq / means to get data-level information. - Depending upon your business specific questions we might have to slice and dice / summarize the data.
Here’s a simple SAS Macro that would help you to quickly find information as to - what are the variables available / last modification date etc. - Give a frequency of occurences / min / max etc info depending on the type of the SAS column info… - Produce a HTML report.
Steps to code the macro…
1. Get the type of the variables proc contents 2. Apply a Proc means with min max of numeric variables…Note: Proc Means does not generate a report for Character variables. 3. Apply a Proc Freq for Character Variables 4. Print an ODS HTML report for the results
/* Explanation of the parameters of the Macro...
dsn - name of the dataset to analyze
numobs - number of observations to include in the dataset
varlist - List of Variables that you need to analyze...use _ALL_ if you want to include all the variables.
%let numvars=; /* Initialize the number of numeric Variables */
%let charvars=; /* Initialize the number of character Variables */
%if %upcase(&varlist) eq _ALL_ %then /*Ifthe user request for all the variables then assign appropriately */
%else /* then find if the vars requested are numeric type or character type */
/* split the varlist into individual macro var names vars1 vars2 etc*/
%let vars&num=%scan(&varlist,&num,' ');
%do %while(&&vars&num ne );
%let num=%eval(&num + 1);
%let vars&num=%upcase(%scan(&varlist,&num,' '));
/*Getthe List of variables in the &dsn dataset and put