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