1. Write a macro in SAS: It should be able to use proc means to print means of a quantitative variable BY a categorical variable (must use a BY line of code), and use proc sgplot to print boxplots of the same quantitative variable by the categorical. Your macro should sort the data first. The user should be able to call the macro, indicating the data set name, and the two variables used in the analysis, as parameters. (You’ll use the macro on some data below…)
SOLUTION:
Use % macro to create a macro block
define 3 variables.
use proc sort to sort the dataset by class variable.
perform proc means on dataset and sgplot
SAS CODE:
%macro analysis (vars=,input=,class=);
proc sort data=&input;
by &class;
run;
proc means data=&input n mean min max
maxdec=2;
class &class;
var &vars;
run;
proc sgplot data=&input;
hbox &vars / category=&class;
run;
%mend analysis;
%analysis(vars=cholesterol,input=sashelp.heart,class=weight_status)
;#call macro
%analysis(vars=returns,input=sashelp.shoes,class=product)
;
Get Answers For Free
Most questions answered within 1 hours.