BookmarkSubscribeRSS Feed
Geo-
Quartz | Level 8

These codes work exactly I wanted

 

 

proc sort data=sashelp.class out=__temp; 
by age;
run;
data __temp1 ;
set __temp; 
by age ;

 

 

however,this get only five columns without any rows for the first time run.When I run it for the second time,it returned an error

 

data __temp2;
set sashelp.class;
by age;
run;

 

 ERROR: BY variables are not properly sorted on data set SASHELP.CLASS.
 Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 FIRST.Age=1 LAST.Age=1 _ERROR_=1 _N_=1
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: There were 2 observations read from the data set SASHELP.CLASS.
 WARNING: The data set WORK.__TEMP2 may be incomplete.  When this step was stopped there were 0 observations and 5 variables.
 WARNING: Data set WORK.__TEMP2 was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01

 

although this is may be easy ,I found little about why and the document did not write anything about this.

 

someone knows please explain a little! thanks!

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data __temp2;
set sashelp.class;
by age notsorted;
run;

age is not sorted in source sashelp.class whereas your __temp is sorted by age as you did using proc sort. 

Astounding
PROC Star

When PROC SORT uses OUT=, it leaves the original data set intact.  The sorted version is stored (in this case) in __TEMP.  So the SET statement has to read:

 

set __temp;

 

Then you can use the BY statement without getting the error.  Don't forget the RUN statement at the end of the DATA step.

himself
Pyrite | Level 9
Hello, i think he had the same set__temp ; statement

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1260 views
  • 2 likes
  • 4 in conversation