From: Jinto83 on
Hi, suppose I want to define a bunch of ratios and I need to do it inside 2 loops:

one loop on carbrand: Toyota, Ford
one loop on variable: Sale, Profit

data aaa;
set bbb;
SALETOYOTA=SALETOYOTA1997+SALETOYOTA1998;
SALEFORD=SALEFORD1997+SALEFORD1998;
PROFITTOYOTA=PROFITTOYOTA1997+PROFITTOYOTA1998;
PROFITFORD=PROFITFORD1997+PROFITFORD1998;
run;

In reality the carbrand contains much more than just 2 companies, otherwise I would just type everything by hand.
May I ask how to do this with array or any loop function?

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Patrick on
It's a bit hard to give you advice only guessing how your data might
look like, but: check out PROC MEANS. This Proc most likely does what
you need.
From: Tom Abernathy on
On Apr 4, 12:31 am, "Jinto83" <jint...(a)sina.com> wrote:
> Hi, suppose I want to define a bunch of ratios and I need to do it inside 2 loops:
>
> one loop on carbrand: Toyota, Ford
> one loop on variable: Sale, Profit
>
> data aaa;
> set bbb;
> SALETOYOTA=SALETOYOTA1997+SALETOYOTA1998;
> SALEFORD=SALEFORD1997+SALEFORD1998;
> PROFITTOYOTA=PROFITTOYOTA1997+PROFITTOYOTA1998;
> PROFITFORD=PROFITFORD1997+PROFITFORD1998;
> run;
>
> In reality the carbrand contains much more than just 2 companies, otherwise I would just type everything by hand.
> May I ask how to do this with array or any loop function?
>
> --- news://freenews.netfront.net/ - complaints: n...(a)netfront.net ---

I agree with Patrick that you should use PROC MEANS (or SUMMARY) to do
your calculations.
To that end you should reformat your variables so that CARBRAND and
YEAR are variables rather implied by the variable names. If you have
not yet entered the data then just enter it differently.