Hello All,
I would highly appreciate if someone tell me how I can sum up the firms in an industry and then take the inverse of the sum. My data looks as follows:
firm year industry
A 2001 OIL
B 2001 OIL
C 2001 OIL
D 2001 OIL
A 2002 OIL
B 2002 OIL
C 2002 OIL
U 2001 SERVICE
V 2001 SERVICE
W 2001 SERVICE
X 2001 SERVICE
Y 2002 SERVICE
U 2002 SERVICE
Z 2002 SERVICE
I want the output to look like
firm year industry SUM invese
A 2001 OIL 4 1/4 =0.25
B 2001 OIL 4 0.25
C 2001 OIL 4 0.25
D 2001 OIL 4 0.25
A 2002 OIL 4 0.25
B 2002 OIL 4 0.25
C 2002 OIL 4 0.25
U 2001 SERVICE 6 0.17
V 2001 SERVICE 6 0.17
W 2001 SERVICE 6 0.17
X 2001 SERVICE 6 0.17
Y 2002 SERVICE 6 0.17
U 2002 SERVICE 6 0.17
Z 2002 SERVICE 6 0.17
Thank you.
You could use:
data have;
input firm $ year industry $;
cards;
A 2001 OIL
B 2001 OIL
C 2001 OIL
D 2001 OIL
A 2002 OIL
B 2002 OIL
C 2002 OIL
U 2001 SERVICE
V 2001 SERVICE
W 2001 SERVICE
X 2001 SERVICE
Y 2002 SERVICE
U 2002 SERVICE
Z 2002 SERVICE
;
proc sql;
create table want as
select *,
count(distinct firm) as count,
1/calculated count as inverse
from have
group by industry
;
quit;
You could use:
data have;
input firm $ year industry $;
cards;
A 2001 OIL
B 2001 OIL
C 2001 OIL
D 2001 OIL
A 2002 OIL
B 2002 OIL
C 2002 OIL
U 2001 SERVICE
V 2001 SERVICE
W 2001 SERVICE
X 2001 SERVICE
Y 2002 SERVICE
U 2002 SERVICE
Z 2002 SERVICE
;
proc sql;
create table want as
select *,
count(distinct firm) as count,
1/calculated count as inverse
from have
group by industry
;
quit;
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.