Proc Freq

SAS Day 37

In previous days, we discussed generating Statistical Summary using Proc Means and Proc Univariate for Continuous Variables(Age, BMI, Height, Weight). 

Now, there is a question, what procedure should we apply to generate Categorical Variables (Sex, Race, Country)?

Today we will show how to use Proc Freq to summarize the Categorical Variables.

MichaelGaida / Pixabay

Proc Freq:

Sample dataset:

Subjid ID: 1-96
Sex: Female, Male
TRT: Treatment Group 1,2 

 

Sample Output:

 

Sample SAS Code:

%macro freq(in= , var= , out1= , out2= , sorter= ); 

proc freq data=&in noprint ; 
tables trt*&var /out=&out1 nopercent; 
run; 

proc sort data=&out1; 
by &var; 
run; 

proc transpose data=&out1 out=&out2(rename=(&var=label)) prefix=c; 
var count; 
by &var; 
id trt; 
run; 

data &out2; 
length label $100.; 
set &out2; 
sorter=&sorter; 
if sorter2=. then sorter2=2; 
drop _name_ _label_;
run; 
%mend freq; 

%freq(in=adsl, var=sex, out1=s1, out2=s, sorter=2);

 

 

 

Warm Attention: This Macro Freq I generated based on my interest, maybe you can add and subtract to tailor your needs.

Happy Practicing!  😷

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: