BookmarkSubscribeRSS Feed
aelatova
Calcite | Level 5

I am trying to combine 5 different data sets, and on the 5th one, it is saying I have an error that my BY variables are not sorted properly, even though I included PROC SORTS in the same way for each data set: 

 

PROC SORT DATA = HypImpt.UTAH_VITALS_2010 OUT= UTAH_VITALS_2010; 
	BY SSN ApptDate; 
	RUN; 
	
PROC SORT DATA = HypImpt.UTAH_VITALS_2011 OUT= UTAH_VITALS_2011; 
	BY SSN ApptDate; 
	RUN; 
	
PROC SORT DATA = HypImpt.UTAH_VITALS_2012 OUT= UTAH_VITALS_2012; 
	BY SSN ApptDate; 
	RUN; 
	
PROC SORT DATA = HypImpt.UTAH_VITALS_2013 OUT= UTAH_VITALS_2013; 
	BY SSN ApptDate; 
	RUN; 
	
PROC SORT DATA = HypImpt.UTAH_VITALS_2014 OUT= UTAH_VITALS_2014; 
	BY SSN ApptDate; 
	RUN; 


DATA	WORK.Vitals_UT;

	SET	HypImpt.UTAH_VITALS_2010
		HypImpt.UTAH_VITALS_2011
		HypImpt.UTAH_VITALS_2012
		HypImpt.UTAH_VITALS_2013
		HypImpt.UTAH_VITALS_2014;
    BY  SSN ApptDate; 
	
	RUN;

The error it gives me is 

ERROR: BY variables are not properly sorted on data set HYPIMPT.UTAH_VITALS_2014.

Any suggestions? 

3 REPLIES 3
PaigeMiller
Diamond | Level 26
The sorted data set is the OUT= data set.

So UTAH_VITALS_2014 is properly sorted, while HypImpt.UTAH_VITALS_2014 is not properly sorted.
--
Paige Miller
LinusH
Tourmaline | Level 20

Hence, even if it's not required, it's good practive to wtite out 

work.

in all saswork table references.

By doing that, it's easier to spot these kind of logical errors in your code.

Data never sleeps
Kurt_Bremser
Super User

You can get this much easier:

data all / view=all;
set
  HypImpt.UTAH_VITALS_2010
  HypImpt.UTAH_VITALS_2011
  HypImpt.UTAH_VITALS_2012
  HypImpt.UTAH_VITALS_2013
  HypImpt.UTAH_VITALS_2014
;
run;

proc sort
  data=all
  out=Vitals_UT
;
by ssn apptdate;
run;

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!
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
  • 3 replies
  • 666 views
  • 0 likes
  • 4 in conversation