SAS day3:
In descriptive statistics, we generally use PROC FREQ to summarize frequency count for the categorical variables, such as Age Group(<=65, >65), SEX(female, male), RACE(Black, White, Asian), and patient Histology. If we want to look at some specific values, I use PROC SQL to select the desired categories. Normally, we write a macro for Proc Freq then manipulate or change the variables for the desired outputs.
Example Code:
%macro freq(in= , var= , out1= );
proc freq data=&in noprint ;
tables strtdose*&var /out=&out1 nopercent;
run;
%mend freq;
*Age group;
%freq(in=adsl1, var=agegrpc, out1=a2);
*Sex;
%freq(in=adsl1, var=sex1, out1=a3);
However, the previous example is build for produce the frequency for different variables, what if we need to producing the frequency count for same variable but different cycles?
Problem:
In oncology studies, the Response variable is one of the most important efficacy endpoints, we would like to use Proc Freq to produce a table to show the response result for patients in each cycle.
Solution:
1. we will write a Proc Freq with a definite variable: Response, but make the cycle as a macro variable
2. we will write a macro do loop outside the proc freq to generate the cycles we need.
3. use Set statement to combine all the frequency count for each cycle.
Code:
%macro c;
%do i=1 %to 50;
proc freq data=pe3(where=(cycle=&i)) noprint ;
tables trtan*response /out=out&i nopercent;
run;
%end;
%mend c;
%c;
data cycresp;
set out1-out61;
proc sort; by sorter response;
run;
Happy SAS coding 🙂 !
Photo by Jess Watters on Unsplash
I am taking notes!