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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 6850 views
  • 2 likes
  • 3 in conversation