DATA Step, Macro, Functions and more

How to select a number of variables by variable

Reply
New User
Posts: 1

How to select a number of variables by variable

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?

Super User
Posts: 17,963

Re: How to select a number of variables by variable

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;

 

Contributor
Posts: 56

Re: How to select a number of variables by variable

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

Re: How to select a number of variables by variable

use outobs=200;
Super User
Posts: 17,963

Re: How to select a number of variables by variable


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?

Ask a Question
Discussion stats
  • 4 replies
  • 107 views
  • 0 likes
  • 3 in conversation