BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ubshams
Quartz | Level 8

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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;
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
  • 2 replies
  • 1009 views
  • 1 like
  • 2 in conversation