BookmarkSubscribeRSS Feed
letmmattos
Calcite | Level 5

hi guys,

 

I have a base on SAS with about 200.000 rows, and there is 10 different agents os that base

 

I need to select 200 rows by agent, with priorities, like:

 

priority   ID           agent

1         005431        A

2         020541        B

3        136751         C

2        057366         A

1        012658         C

3        057317         B

1        012856         B

 

The way i need to select them is:

first, put everything with priority 1 for agent A

if its not complete with 200 rows, put priority 2

and so on

 

anyone knows how can I do it?

4 REPLIES 4
Reeza
Super User

1. Sort by Agent, Priority

2. Count records for each by group and take the top 200 per agent

 

proc sort data=have;

by agent priority;

run;

 

data want;

set have;

by agent;

if first.agent then count=1;

else count+1;

if count <=200;

run;

 

lakshmi_74
Quartz | Level 8
proc sql outobs=3;
create table want as
select * from have group by agent, priority;
quit;
proc print data=have;run;
lakshmi_74
Quartz | Level 8
use outobs=200;
Reeza
Super User

@lakshmi_74 wrote:
proc sql outobs=3;
create table want as
select * from have group by agent, priority;
quit;
proc print data=have;run;

This would generate 200 total observations, not 200 per agent?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1091 views
  • 0 likes
  • 3 in conversation