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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 978 views
  • 0 likes
  • 3 in conversation