BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Hi community,

 

Here i have a example dataset 

 

data xxx;
input col1 col2 col3;
cards;
20 20 25.34 
55 10 22.33
42 55 22.22
22 45 14.22
run;
proc print;
run;

I want to summarize the value using

 

Var

Yes

No

col1≥40

2

0

col2/col1 ratio≥1

1

0

col3≥25

1.5

0

 

The output should be like,

Condition:

if col11 ge 40 and ratio ge 1 and col3 ge 25  result = 4.5

 

 

Result 
2.5(0+1+1.5)
3(2+1+0)
2(2+0+0)
0(0+0+0)

I'm looking for Result column.

I can done this by calculate individual column. but that takes more time and line of codes.

Can anyone suggest me the effective codes to resolve this method.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Make use of the fact that boolean operations result in either 0 (false) or 1 (true), so it ends up a simple calculation:

data have;
input col1 col2 col3;
cards;
20 20 25.34 
55 10 22.33
42 55 22.22
22 45 14.22
;
run;

data want;
set have;
result =
  (col1 >= 40) * 2 +
  (col2/col1 >= 1) +
  (col3 >= 25) * 1.5
;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Make use of the fact that boolean operations result in either 0 (false) or 1 (true), so it ends up a simple calculation:

data have;
input col1 col2 col3;
cards;
20 20 25.34 
55 10 22.33
42 55 22.22
22 45 14.22
;
run;

data want;
set have;
result =
  (col1 >= 40) * 2 +
  (col2/col1 >= 1) +
  (col3 >= 25) * 1.5
;
run;
Sathish_jammy
Lapis Lazuli | Level 10

Thank you for your help.. @Kurt_Bremser

 

I have a addition condition in this step 

data have;
input gen$ col1 col2 col3;
cards;
m 20 20 25.34 
f 55 10 22.33
m 42 55 22.22
f 22 45 14.22
;
run;

data want;
set have;
result =
  (col1 >= 40) * 2 +
  (col2/col1 >= 1) +
  (col3 >= 25) * 1.5
;
run;

the condition is 

Var

Yes

No

col2/col1≥0.9 (Male) and  col2/col1≥0.8 (Female)            

1

0

 

how to add this in the step.

Thanks in advance!

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