I am creating a variable4 which takes the Month 4 value of variable 3 and multiplies it by the value of
(variable2/variable3). Right now I am manually typing the Month 4 value of 105 to get create variable4. Can this be automated by code? I created a new column with _N values but stuck on whether to use this or not.
data have;
input month variable1 variable2 variable3;
cards;
1 501 500 95
2 500 502 96
3 510 502 101
4 509 400 105
5 506 402 106
6 512 400 98
7 400 399 95
;
run;
data want;
set have;
variable4= (variable2/variable3)*105;
n = _N_;
run;
Thanks!
Sure. Here's one way:
data want;
if _n_=1 then set have (rename=(variable3=month4_value) where=(month=4));
set have;
variable4= (variable2/variable3)*month4_value;
n = _N_;
run;
Sure. Here's one way:
data want;
if _n_=1 then set have (rename=(variable3=month4_value) where=(month=4));
set have;
variable4= (variable2/variable3)*month4_value;
n = _N_;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.