BookmarkSubscribeRSS Feed
dishant
Calcite | Level 5

Hi all,

I have Following data In which I want to output not sorted data in another dataset. How??

data  t2;

input subjid rowno tmpoint & $25.;

datalines;

101 1 4 hr

101 2 8 hr

101 3 12 hr

101 4 16 hr

102 1 4 hr

102 2 12 hr

102 3 16 hr

102 4 8 hr

run;

Your help will help me a lot.Thanks In Advance..

Regards,

Dishant

5 REPLIES 5
TarunKumar
Pyrite | Level 9

don't understand what do you want to do. Please eleobrate the same.

dishant
Calcite | Level 5

Hi,

I Have data like this,

data  t2;

input subjid rowno tmpoint & $25.;

datalines;

101 1 4 hr

101 2 8 hr

101 3 12 hr

101 4 16 hr

102 1 4 hr

102 3 12 hr

102 4 16 hr

102 2 8 hr

run;

Now In Upper data I want output those observations which are not sorted.How?

TarunKumar
Pyrite | Level 9

not sure but i think this will work .

data  t2;

input subjid rowno tmpoint & $25.;

datalines;

101 1 4 hr

101 2 8 hr

101 3 12 hr

101 4 16 hr

102 1 4 hr

102 3 12 hr

102 4 16 hr

102 2 8 hr

;

run;

data t2_1;

set t2;

by subjid;

retain cnt  0;

if first.subjid then cnt = 0;

cnt+1;

if cnt ~= rowno then output  t2_1;

run;

dishant
Calcite | Level 5

Hi Tarunkumar,

Thanks and Appreciate For your help and time. This Takes me a new level of Thinking .

Peter_C
Rhodochrosite | Level 12

Another thought:

Where order is defined by a numeric var, use the DIF() function like :

Data ordered unordered ;

Set your.data ;

by subjID ;

drop difff ;

Difff = dif( rowno ) ;

if first.subjid then output ordered ;

Else  if difff GE 0 then output ordered ;

else output unordered ;

Run ;

Message was edited by: Peter Crawford To fix typos after submitting

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

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
  • 5 replies
  • 1893 views
  • 3 likes
  • 3 in conversation