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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: