BookmarkSubscribeRSS Feed
Martina4
Calcite | Level 5

Hello all,

 

I am trying to gather the means and standard errors of harvest yields from my data. I have entered the following code...

 

proc sort data=WORK.SSG2016harvests;
by legume trt harvest;
proc means data=WORK.SSG2016harvests mean stderr;
var sorgyd;
by harvest;
output out = c mean=sorgyd sorgSE;
run;

 

However, I keep receiving the following error message when I try to run it...

ERROR: Data set WORK.SSG2016HARVESTS is not sorted in ascending sequence. The current BY group has Harvest = Total and the next BY group has Harvest = 1.
 
There are 5 different harvests labeled as 1, 2, 3, 4, total.
I am stumped on how to solve this, and appreciate some input!
 
Thank you!
2 REPLIES 2
PaigeMiller
Diamond | Level 26

Total sorts after the numbers, in the default SAS sort order.

 

So, when total comes first, it is not in the proper sorted order.

 

To fix this, use either:

 

by harvest notsorted;

OR

 

class harvest;
--
Paige Miller
Astounding
PROC Star

There are two issues to attend to.  First, what groupings do you want statistics for?  For each harvest?  Then use:

 

by harvest;

 

But use that in BOTH procedures, don't change it from one procedure to the next.  On the other hand, if you want separate statistics for each treatment within each procedure, use:

 

by trt harvest;

 

Again, use the same BY statement for BOTH procedures.

 

The other issue is the request for the standard errors.  You have to specify which statistic you are asking for.  So the OUTPUT statement would look like this:

 

output out=c mean=sorgyd stderr=sorgSE;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 6210 views
  • 2 likes
  • 3 in conversation