BookmarkSubscribeRSS Feed
Sathish_jammy
Lapis Lazuli | Level 10

Hi all,

 

Here I have a sample dataset.

In the calculation method, I get confused in the line which I mention as comment

data have;
input age bmi ht dd;
cards;
25 26.2 176 2
56 25.3 156 1
84 45.2 182 3
57 22.8 145 2
78 32.2 155 5
69 21.6 103 4;

run;
data want;
set have;
value =  
	1.235 +  
	(0.2*age) +  
	(1.13 * (dd=2)*1) + 
	(1.21*ht);
run;

/**(1.13 * dd[yes=1,no=0])) +**/
/**(dd=2,1)YES, (dd=Other dd value)NO**/
/**Here the condition reached for dd=2 so (1.13*1) else dd=(any) (1.13*0)**/


Here the code states dd=2 so (Yes) it taken as 1

How do I add the another one condition for dd=1 in the same parameter. (dd=2,1 (YES) else (NO))

Thanks in advance!

2 REPLIES 2
Astounding
PROC Star

I can't say whether the logic is correct or not.  But you have to realize that the section you are adding to the formula would add 0 every time, so there is really no need to add it in this case.  At any rate, here's what the additional piece of the formula would look like:

 

(1.13 * (dd=1) * 0) +

 

If it's possible that DD could be neither 1 nor 2, you might want:

 

(1.13 * (dd ne 1) * 0) +

 

But either way, the net result is adding 0 to the original formula.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 958 views
  • 1 like
  • 3 in conversation