BookmarkSubscribeRSS Feed
sjl347
Calcite | Level 5

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
PaigeMiller
Diamond | Level 26

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
ballardw
Super User

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.

PaigeMiller
Diamond | Level 26

@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
ballardw
Super User

@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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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