BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
joon1
Quartz | Level 8

Hi,

I would like to pick the largest two auditors in sales within the same two-digit sic industry. For instance, I would like to pick observations 1 and 2 out of industry where the second-digit sic code is 1 and observations 7 and 8 out of the second-digit sic code is 7.  Which SAS program is proper? Your help will be greatly appreciated.

 

 

obscyearsic2epidsumauditorsalesumsicsale
12016134115661350217586.14
22016142009774011.517586.14
320161420190845.57717586.14
420161206000010.4117586.14
5201616560900126.65317586.14
6201612.77E+08017586.14
72016742018021691.3565106.032
820167185000332516.8635106.032
92016719900031845.6785106.032
10201677290001552.1355106.032
11201675.77E+0805106.032

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

@joon1  do you mean something like this?

 

data want;

set have;

by sic;

if first.sic then n=0;

n+1;

if n in (1,2);

run;

 

View solution in original post

5 REPLIES 5
Reeza
Super User

See the approach outlined here:

http://documentation.sas.com/?docsetId=proc&docsetTarget=n0afy7c5m16m9dn1s60z9krjmwxq.htm&docsetVers...

 


@joon1 wrote:

Hi,

I would like to pick the largest two auditors in sales within the same two-digit sic industry. For instance, I would like to pick observations 1 and 2 out of industry where the second-digit sic code is 1 and observations 7 and 8 out of the second-digit sic code is 7.  Which SAS program is proper? Your help will be greatly appreciated.

 

 

obs cyear sic2 epid sumauditorsale sumsicsale
1 2016 1 3411566 13502 17586.14
2 2016 1 4200977 4011.5 17586.14
3 2016 1 4201908 45.577 17586.14
4 2016 1 20600001 0.41 17586.14
5 2016 1 65609001 26.653 17586.14
6 2016 1 2.77E+08 0 17586.14
7 2016 7 4201802 1691.356 5106.032
8 2016 7 18500033 2516.863 5106.032
9 2016 7 19900031 845.678 5106.032
10 2016 7 72900015 52.135 5106.032
11 2016 7 5.77E+08 0 5106.032

 

Thank you




novinosrin
Tourmaline | Level 20

@joon1  do you mean something like this?

 

data want;

set have;

by sic;

if first.sic then n=0;

n+1;

if n in (1,2);

run;

 

MINX
Obsidian | Level 7

You can try Proc Rank as:

 

proc rank data=have descending ties=low /*ties=dense*/
out=want(where=(order<=2));
by sic2 notsorted;
var sumauditorsale; ranks order;
run;

Reeza
Super User

What about ties? One of those answers accounts for ties, the other does not. 

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
  • 5 replies
  • 777 views
  • 2 likes
  • 4 in conversation