There is a DATA step solution. (Hmm...maybe there's a DATA step solution to everything.)
Since this requires BY-group processing, start by loading the data into partitions:
libname mycas cas; data mycas.have(partition=(id) orderby=(distance) replace=yes); input id var1 var2 var3 distance; datalines; 1 1 1 1 0.2 1 2 1 2 0.3 2 1 1 3 0.9 2 1 2 1 0.2 3 1 3 2 0.1 ; run;
Then, use the SESSREF= DATA statement argument to insist that the DATA step runs in CAS:
data mycas.want / sessref=casauto;
set mycas.have;
by id distance;
if first.id then output;
run;
Finally, check the work:
proc print data=mycas.want; run;
There's lots of excellent DATA step in CAS documentation, such as the following:
(I made an update to this post because I left off the ORDERBY= data set option on the first DATA step. With the option, the table is already organized according to the BY statement in the second DATA step--avoiding any reorganizing the data to sort it. Without the data set option, the second DATA step has to make a temporary copy of the table--partitioning and sorting it.)
thanks, it works!!!!
you save my life
thank you for your help !!!!
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.