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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 555 views
  • 1 like
  • 3 in conversation