Help me with a data procedure

Reply
Frequent Contributor
Posts: 122

Help me with a data procedure

I want to get sum of a variable wgt for each date and firm id. I wrote the following simple code, but didn't get what I want. Can someone have a look and let me know what's wrong.

proc sort data=have; by date firm; run;

data want; set have; by date firm; summ=sum(wgt); run;

Thanks.

Respected Advisor
Posts: 4,173

Re: Help me with a data procedure

data want;

set have;

by date firm;

retain summ;

summ=sum(summ,wgt);

if last.firm then

do;

     output;

     call missing(summ);

end;

run;

Trusted Advisor
Posts: 1,137

Re: Help me with a data procedure

Alternatively,

data want;

set have;

by date firm;

retain summ;

    if first.firm then summ=wgt;

    else summ+wgt;

run;

Thanks,

Jagadish

Thanks,
Jag
Respected Advisor
Posts: 3,156

Re: Help me with a data procedure

Posted in reply to Jagadishkatam

Even less verbose:

data want;

set have;

by date firm;

sum+wgt+(-first.firm*sum);

run;

Haikuo

Ask a Question
Discussion stats
  • 3 replies
  • 179 views
  • 2 likes
  • 4 in conversation