If I wasn't comfortable with arrays that's where I would start.
For one thing the concept is around in very many programming languages so you can apply the skills learned in SAS elsewhere OR use examples written for other languages once you know the general syntax differences.
Hi,
Can anyone help me to understand this code.?
Thanks..
Thanks all.
I am still confused to use HASH
Not sure this is guaranteed to find all of the groups, but it sounds like what you requested.
%macro loop;
proc sql ;
%let nobs=0;
%do %until (&nobs=0) ;
create table next as
select * from have
where group not in (select group from want)
having count = max(count)
order by count desc
;
%let nobs=&sqlobs ;
insert into want select * from next(obs=1);
%end;
quit;
%mend loop;
data want; set have (obs=0); run;
%loop;
the code is not considering all the id's.
Xia and Hai.Kuo 's code is giving correct results but the problem is i didn't understand the code what is happening there, this leads to confusion in replicate the code according to my original scenario...
Thanks.
Use array instead.
data have;
input ID Group$ Count;
cards;
101 A 180
101 B 90
101 C 60
102 A 90
102 B 60
102 C 50
103 A 60
103 B 50
103 C 70
;
run;
proc sort data=have;by id descending Count;run;
data want;
set have;
by id;
array key{99999} $ 32 _temporary_;
retain found;
if first.id then found=.;
if not found and group not in key then do;output;n+1;key{n}=group;found=1;end;
drop found n;
run;
Xia Keshan
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.