BookmarkSubscribeRSS Feed
improvingCas
Calcite | Level 5
Hi !!
im new to sas viya

i don't know how to find min value of column by group

i have mycas.dist data like

id var1 var2 var3 distance
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

and i want to make table using mycas.dist like below table

id var1 var2 var3 distance
1 1 1 1 0.2
2 1 2 1 0.2
3 1 3 2 0.1

can i do it using cas data?
2 REPLIES 2
MikeMcKiernan
SAS Employee

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:

BY-group processing in CAS

 

(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.)

improvingCas
Calcite | Level 5

thanks, it works!!!! 

 

you save my life 

 

thank you for your help !!!!

sas-innovate-white.png

Our biggest data and AI event of the year.

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.

 

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
  • 2 replies
  • 1619 views
  • 0 likes
  • 2 in conversation