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

Hi all. I would like to transform table 1 to table 2.

 

Table 2 means the bigger value has to times all the previous values. How do I write the code to show such increment? Thanks!

 

Table 1:

 Value1       Value2      Value3

5                   6                  7

 

 

Table 2:

 Value1       Value2      Value3

5                  5*6               5*6*7

1 ACCEPTED SOLUTION
7 REPLIES 7
SASKiwi
PROC Star

Looks like you are drip feeding us part of an unspecified bigger problem. With only 2 variables needing calculation just hard-code the result:

data Have;
  Value1 = 5;
  Value2 = 6;
  Value3 = 7;
run;

data Want;
  set Have;
  Value2 = Value2 * Value1;
  Value3 = Value3 * Value2;
  put _all_;
run;

Or if this example is going to grow then here is a more flexible way:

data Want;
set Have;
array values (3) Value1 - Value3;
do i = 1 to 2;
Values(i+1) = Values(i+1) * Values(i);
end;
put _all_;
run;

 

di_niu0
Obsidian | Level 7
What if I have many values? How to expand v{i} = v{i} * v{i-1}; ?
di_niu0
Obsidian | Level 7
Got it. Thanks!
di_niu0
Obsidian | Level 7

Hi all. I would like to write codes to transform table from Table 1 to Table 2. Thank you! 

 

Table 1:

ID      Value1      Value2        Value3

1         1                   2                 3

2        4                  5                 6

3        7                  8                 9

 

Table 2:

ID      Value4        Value5                Value6

1         1-(1-1)         1-(1-1)(1-2)         1-(1-1)(1-2)(1-3)

2        1-(1-4)         1-(1-4)(1-5)       1-(1-4)(1-5)(1-6)           

3        1-(1-7)         1-(1-7)(1-8)        1-(1-7)(1-8)(1-9)

 

 

 

ballardw
Super User

Are the (1-1)(1-2)  supposed to be multiplication? And follow normal rules of arithmetic order such as the result of  1-(1-1)(1-2)  is 1 - (result of (1-1) times (1-2) )?

I ask because we get inconsistent usages.

 

What metric are you using to define "efficient"? Fewer lines of code? Execution time? Memory use? Some combination of these?

 

If this is a subset of a larger problem you should say so because your number of variables is low enough that you don't gain much in different approaches that might appear if there were 50 values per observation.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register 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
  • 7 replies
  • 1073 views
  • 0 likes
  • 4 in conversation