BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ballardw
Super User

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.

kumarK
Quartz | Level 8

Hi,

Can anyone help me to understand this code.?

Thanks..

kumarK
Quartz | Level 8

Thanks all.

I am still confused to use HASH Smiley Happy

Tom
Super User Tom
Super User

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;

kumarK
Quartz | Level 8

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.

Ksharp
Super User

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

sas-innovate-2024.png

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.

 

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.

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
  • 20 replies
  • 2267 views
  • 11 likes
  • 8 in conversation