BookmarkSubscribeRSS Feed
hhchenfx
Rhodochrosite | Level 12

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

;

4 REPLIES 4
Scott_Mitchell
Quartz | Level 8

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

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

hhchenfx
Rhodochrosite | Level 12

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

ballardw
Super User

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?

hhchenfx
Rhodochrosite | Level 12

I only have 2 rows data.

HHC

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1785 views
  • 0 likes
  • 3 in conversation