Calcite | Level 5

## Proc Univariate Coding Help

Hi there, I am an M.Sc student with a question about coding for proc univariate.

I am wondering when it is appropriate to use a by statement when writing the code for Proc Univariate?

Here are my codes, and I am wondering which is the correct one

proc sort data=____;

by trt dur;

proc univariate data=____ normal plot;

var ____;

by trt dur;

run;

OR would this be the right code

proc univariate data=____ normal plot;

var ____

run;

trt=treatment

dur= duration

I have 5 treatments, with 2 time durations per treatment

4 REPLIES 4
Diamond | Level 26

## Re: Proc Univariate Coding Help

If you want to get statistics from PROC UNIVARIATE for each combination of TRT and DUR, then the first code is correct.

If you want to get statistics from PROC UNIVARIATE over the entire data set, then the second code is correct.

--
Paige Miller
Super User

## Re: Proc Univariate Coding Help

Or separate analysis only by trt or only by dur then only one variable on the BY statement.

Note that each option other than the overall analysis would require different sorts of the data prior to the Proc Univariate as data sort BY order must match the BY statement.

Diamond | Level 26

## Re: Proc Univariate Coding Help

@ballardw wrote:

Or separate analysis only by trt or only by dur then only one variable on the BY statement.

Note that each option other than the overall analysis would require different sorts of the data prior to the Proc Univariate as data sort BY order must match the BY statement.

Depending on what statistics are needed from this analysis, PROC SUMMARY can do this without different sorts of the data.

--
Paige Miller
Super User

## Re: Proc Univariate Coding Help

@PaigeMiller wrote:

@ballardw wrote:

Or separate analysis only by trt or only by dur then only one variable on the BY statement.

Note that each option other than the overall analysis would require different sorts of the data prior to the Proc Univariate as data sort BY order must match the BY statement.

Depending on what statistics are needed from this analysis, PROC SUMMARY can do this without different sorts of the data.

Absolutely. With the example code showing requests for plots and not knowing if @sjl347 might be looking for the other by group outputs I thought it might be helpful to remind a new user about the sort requirement for different by groups.

Discussion stats
• 4 replies
• 750 views
• 2 likes
• 3 in conversation