Starbucks
Starbucks

Reputation: 1568

SAS - Creating Plots for ALL variables

Is there an easy way to create plots for all variables instead of listing each variable?

Rather:

proc sgplot data = insurance; histogram YOJ; run; 
proc sgplot data = insurance; histogram INCOME; run; 
proc sgplot data = insurance; histogram HOME_VAL; run; 
proc sgplot data = insurance; histogram CAR_AGE; run;

What if I had 100 more histograms I wanted to look at alone without using the univariate procedure? Why would I have to write out each line? Is there an easier way?

Thanks!

Upvotes: 0

Views: 1544

Answers (1)

Reeza
Reeza

Reputation: 21294

You can use proc univariate to generate stats and the histogram for all variables. Add the ODS SELECT statement to include only the histogram, it's currently commented out.

*ods select histogram;
proc univariate data=sashelp.class;
histogram;
run;quit;

EDIT: I tried using the numeric and that didn't work, so besides the code above all I could think of was a macro. I would query the names from SASHELP.VCOLUMN and use the names in the code.

proc sql noprint;
select name into :hist_state1- 
from sashelp.vcolumn
where upper(libname)='SASHELP'
and upper(memname)='CLASS'
and type='num';
quit;

%let nobs=&sqlobs;


%macro generate_histogram;

%do i=1 %to &nobs;

proc sgplot data=sashelp.class;
title "Histogram of &&&hist_state&i";
histogram &&&hist_state&i;
run;quit;


%end;

%mend;

%generate_histogram;

Upvotes: 1

Related Questions