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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1439 views
  • 0 likes
  • 2 in conversation