BookmarkSubscribeRSS Feed
nottyprof
Calcite | Level 5

How do you find proportions in sas with the if statement. Say you given couple of numbers say 1 to 50 with a variable named BMI, how do you find proportions of i) BMI < 25, ii)at least 25 but less than 30 and iii) 30 or greater? 

 

25.24..20.2320.272730222523242223262121192021202530243518...85.5355.5158567159465175476823.21.25.2323.172022.2720282922.192624211921232022251914.231917272933.2024.262624212121243102620.22282329029232023.22232322192123.2626.02521193320232419230202229263819252322..2025242121

 

BMI
25.06
.
24.21
.
.
19.84
.
23.23
20.33
.
27.46
27.44
29.95
22.44
24.96
23.17
24.21
22.31
23.38
25.74
20.80
21.03
19.00
19.85
21.03
20.48
24.63
30.11
23.73
34.97
18.48
.
.
.
84.50
.
53.06
54.61
.
51.35
58.23
56.36
70.89
58.57
46.49
50.50
74.55
46.76
68.20
23.11
.
20.63
.
25.49
.
23.23
22.89
.
17.16
19.84
21.95
.
27.19
19.57
28.36
29.26
22.49
.
18.79
25.82
23.71
20.80
19.48
20.50
22.59
20.23
21.70
25.06
19.14
14.12
.
23.05
19.13
16.95
26.78
29.05
33.20
.
19.57
24.33
.
26.38
26.25
23.57
21.14
20.80
21.45
24.09
30.54
0.00
25.66
19.97
.
21.63
27.89
22.71
29.05
0.00
29.18
22.66
19.97
22.80
.
21.87
22.80
23.38
21.56
19.02
20.77
23.04
.
25.92
26.29
3045.06
0.00
25.00
20.90
18.95
33.47
20.47
22.59
23.77
18.88
23.17
0.00
20.47
22.46
29.26
25.93
37.65
19.39
24.96
22.67
22.04
.
.
19.58
24.51
23.99
21.45
20.98

 

 

 

2 REPLIES 2
Reeza
Super User
Create your categories and then run a PROC FREQ on the output.

https://gist.github.com/statgeek/227565537f3dffcd8627f1fe2eff844f

nottyprof
Calcite | Level 5
Found it out later.

option ps=10 1s=40;
data in;
input BMI;
title 'Question 4 Respondents Body mass index (BMI)';
if 10 le bmi le 24.99 then bmiclass='Respondents BMI <25';
else if 25 le bmi le 29.99 then bmiclass='Res BMI 25 to 29.99';
else if 30 le bmi le 40 then bmiclass= 'Respondents BMI <30';
cards;
25.06
19.84
23.23
20.33
27.44
29.95
22.44
24.96
23.17
25.74
20.80
21.03
18.47
19.85
21.03
20.48
30.11
23.73
18.48
24.12
24.82
25.62
21.13
21.25
31.00
23.11
23.41
17.16
19.84
21.95
28.36
29.26
18.79
20.80
19.48
20.50
20.23
21.70
25.06
19.14
14.12
23.05
19.13
26.78
29.05
33.20
19.57
26.25
23.57
21.14
20.80
21.45
24.09
30.54
27.89
22.71
29.05
22.66
19.97
22.80
22.80
23.38
20.77
23.04
21.00
20.90
18.95
22.59
23.77
23.17
20.47
22.46
28.34
25.93
19.39
24.96
22.67
22.04
23.99
21.45
20.98
24.21
27.46
24.21
23.03
23.38
24.63
34.97
38.41
23.34
26.47
32.22
26.62
22.96
33.89
20.63
25.49
22.89
27.19
19.57
22.49
25.82
23.71
22.59
16.95
24.33
26.38
25.66
19.97
21.63
29.18
21.87
21.56
19.02
25.92
26.29
25.00
33.47
20.47
18.88
37.65
19.58
24.51
run;

proc freq;
tables bmiclass;
run;

Cards could be replaced with dataline

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1435 views
  • 0 likes
  • 2 in conversation