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


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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

1 REPLY 1
art297
Opal | Level 21

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;

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!

What is Bayesian Analysis?

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.

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
  • 1 reply
  • 601 views
  • 0 likes
  • 2 in conversation