## Help with rule for each set of variables

Super Contributor
Posts: 506

# Help with rule for each set of variables

Hello Everyone,

I have a data of a 3 set of variable a1-a3 b1-b3 c1-c3.

For a1-a3, I want to calculate a ratio of value*2.0/lag(value)

For b1-b3, I want to calculate a ratio of value*1.0/lag(value)

For c1-c3, I want to calculate a ratio of value*0.5/lag(value)

I don't know how to set condition based on variable name.

Any help is very much appreciated.

Thank you,

HHC

data have;

input id a1 a2 a3 b1 b2 b3 c1 c2 c3;

datalines;

1     1 2 3 11 12 13 111 112 113

2     5 6 7 55 56 57 555 556 557

;

Super Contributor
Posts: 312

## Re: Help with rule for each set of variables

Can you please provide your desired output based on the attached sample?

This will ensure that we are interpreting what you are saying correctly.

Super Contributor
Posts: 506

## Re: Help with rule for each set of variables

Hi Scott,

My output should look like:

1     1 2 3 11 12 13 111 112 113

2     5 6 7 55 56 57 555 556 557

3     0.4 0.66

Essentially, there will be another row added to the file, and this row report the ratio.

Thank you,

HHC

Super User
Posts: 13,583

## Re: Help with rule for each set of variables

Do you have more than 2 rows of data? Is the same ratio to be calculated between each pair of input rows? Would row 4 in output be the 3rd input row and row 5 the ratio of 2nd and 3rd input rows or rows 4 and 5 be input rows 3 and 4 with output row 6 the ratio?

Super Contributor
Posts: 506

## Re: Help with rule for each set of variables

I only have 2 rows data.

HHC

Discussion stats
• 4 replies
• 225 views
• 0 likes
• 3 in conversation