options ls=80; data one; input x @@; retain lastx .; if x < lastx then unsort = '*'; else unsort = ' '; thelast = lastx; lastx = x; datalines; 1 3 4 7 8 12 15 18 19 22 ; data two; input x @@; retain lastx .; if x < lastx then unsort = '*'; else unsort = ' '; thelast = lastx; lastx = x; datalines; 1 3 4 7 8 6 15 18 12 22 ; data three; input x @@; * retain lastx .; if x < lastx then unsort = '*'; else unsort = ' '; thelast = lastx; lastx = x; datalines; 1 3 4 7 8 6 15 18 12 22 ; title 'Observations in Order'; proc print data=one; run; title 'Two Obs Out of Order'; proc print data=two; run; title 'No retain statement'; proc print data=three; run;