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;

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 898 views
  • 0 likes
  • 2 in conversation