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!

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