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 !!!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.