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
Opal | Level 21

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 257 views
  • 0 likes
  • 4 in conversation