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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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