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 out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.