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

I have a dataset with variables date, firm id, dummy and asset. What I want to achieve is for each date, each firm id, calculate a weight for each observation according to asset when dummy=0, and do the same for dummy=1. A simple example is as below

date     firm id     dummy     asset     weight

1          A               0          50          50/(50+50)=0.5

1          A               0          50          50/(50+50)=0.5

1          A               1          20          20/(20+80)=0.2

1          A               1          80          80/(20+80)=0.8

I want to get the weight shown above. How can I use proc sql to get the results? Or other ways?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hi,

Please try the below code

data have;

    input date firm_id$ dummy asset;

cards;

1          A               0          50         

1          A               0          50         

1          A               1          20         

1          A               1          80         

;

proc sql;

    create table want as select date,firm_id,dummy,asset,asset/sum(asset) as weight from have

    group by date,firm_id,dummy;

quit;

Thanks,

Jagadish

Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

Hi,

Please try the below code

data have;

    input date firm_id$ dummy asset;

cards;

1          A               0          50         

1          A               0          50         

1          A               1          20         

1          A               1          80         

;

proc sql;

    create table want as select date,firm_id,dummy,asset,asset/sum(asset) as weight from have

    group by date,firm_id,dummy;

quit;

Thanks,

Jagadish

Thanks,
Jag
SeanZ
Obsidian | Level 7

Thanks. I am going to try it, but it seems to be correct.

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
  • 2 replies
  • 1741 views
  • 0 likes
  • 2 in conversation