Hello. I've been struggling with question b. help needed
. The following data sets contain BMI measurements for the baseline, 3 months, and 9 months, for the intervention and control group patients.
data int;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
101 int 34.5 33.8 31.1
102 int 30.7 29.6 27.3
103 int 32.0 30.7 27.5
105 int 34.6 33.5 33.3
106 int 37.6 34.9 30.1
107 int 30.2 29.2 28.7
108 int 37.2 36.0 35.1
109 int 35.2 33.3 33.7
111 int 32.3 31.4 29.4
;
data cnt;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
401 cnt 33.7 33.4 33.2
402 cnt 31.2 30.1 29.8
404 cnt 30.8 31.1 31.8
406 cnt 29.2 29.0 28.9
408 cnt 27.7 27.3 27.9
409 cnt 33.8 32.9 31.4
a) Concatenate the data sets and compute the change in BMI between the baseline and 9 months. Your output should look like this.
Obs | ID | GROUP | BMI_base | BMI_3mos | BMI_9mos | BMI_change |
1 | 101 | int | 34.5 | 33.8 | 31.1 | -3.4 |
2 | 102 | int | 30.7 | 29.6 | 27.3 | -3.4 |
3 | 103 | int | 32.0 | 30.7 | 27.5 | -4.5 |
4 | 105 | int | 34.6 | 33.5 | 33.3 | -1.3 |
5 | 106 | int | 37.6 | 34.9 | 30.1 | -7.5 |
6 | 107 | int | 30.2 | 29.2 | 28.7 | -1.5 |
7 | 108 | int | 37.2 | 36.0 | 35.1 | -2.1 |
8 | 109 | int | 35.2 | 33.3 | 33.7 | -1.5 |
9 | 111 | int | 32.3 | 31.4 | 29.4 | -2.9 |
10 | 401 | cnt | 33.7 | 33.4 | 33.2 | -0.5 |
11 | 402 | cnt | 31.2 | 30.1 | 29.8 | -1.4 |
12 | 404 | cnt | 30.8 | 31.1 | 31.8 | 1.0 |
13 | 406 | cnt | 29.2 | 29.0 | 28.9 | -0.3 |
14 | 408 | cnt | 27.7 | 27.3 | 27.9 | 0.2 |
15 | 409 | cnt | 33.8 | 32.9 | 31.4 | -2.4 |
b) Remove the intervention group patients whose BMI decreased by less than 3 points and also the control group patients whose BMI increased over time. Your output should look like this:
Obs | ID | GROUP | BMI_base | BMI_3mos | BMI_9mos |
1 | 101 | int | 34.5 | 33.8 | 31.1 |
2 | 102 | int | 30.7 | 29.6 | 27.3 |
3 | 103 | int | 32.0 | 30.7 | 27.5 |
4 | 106 | int | 37.6 | 34.9 | 30.1 |
5 | 401 | cnt | 33.7 | 33.4 | 33.2 |
6 | 402 | cnt | 31.2 | 30.1 | 29.8 |
7 | 406 | cnt | 29.2 | 29.0 | 28.9 |
8 | 409 | cnt | 33.8 | 32.9 | 31.4 |
Please show what you've tried on your assignment so far and we can help from there.
@NhatHoang1 wrote:
Hello. I've been struggling with question b. help needed
. The following data sets contain BMI measurements for the baseline, 3 months, and 9 months, for the intervention and control group patients.
data int;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
101 int 34.5 33.8 31.1
102 int 30.7 29.6 27.3
103 int 32.0 30.7 27.5
105 int 34.6 33.5 33.3
106 int 37.6 34.9 30.1
107 int 30.2 29.2 28.7
108 int 37.2 36.0 35.1
109 int 35.2 33.3 33.7
111 int 32.3 31.4 29.4
;
data cnt;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
401 cnt 33.7 33.4 33.2
402 cnt 31.2 30.1 29.8
404 cnt 30.8 31.1 31.8
406 cnt 29.2 29.0 28.9
408 cnt 27.7 27.3 27.9
409 cnt 33.8 32.9 31.4
a) Concatenate the data sets and compute the change in BMI between the baseline and 9 months. Your output should look like this.
Obs
ID
GROUP
BMI_base
BMI_3mos
BMI_9mos
BMI_change
1
101
int
34.5
33.8
31.1
-3.4
2
102
int
30.7
29.6
27.3
-3.4
3
103
int
32.0
30.7
27.5
-4.5
4
105
int
34.6
33.5
33.3
-1.3
5
106
int
37.6
34.9
30.1
-7.5
6
107
int
30.2
29.2
28.7
-1.5
7
108
int
37.2
36.0
35.1
-2.1
8
109
int
35.2
33.3
33.7
-1.5
9
111
int
32.3
31.4
29.4
-2.9
10
401
cnt
33.7
33.4
33.2
-0.5
11
402
cnt
31.2
30.1
29.8
-1.4
12
404
cnt
30.8
31.1
31.8
1.0
13
406
cnt
29.2
29.0
28.9
-0.3
14
408
cnt
27.7
27.3
27.9
0.2
15
409
cnt
33.8
32.9
31.4
-2.4
b) Remove the intervention group patients whose BMI decreased by less than 3 points and also the control group patients whose BMI increased over time. Your output should look like this:
Obs
ID
GROUP
BMI_base
BMI_3mos
BMI_9mos
1
101
int
34.5
33.8
31.1
2
102
int
30.7
29.6
27.3
3
103
int
32.0
30.7
27.5
4
106
int
37.6
34.9
30.1
5
401
cnt
33.7
33.4
33.2
6
402
cnt
31.2
30.1
29.8
7
406
cnt
29.2
29.0
28.9
8
409
cnt
33.8
32.9
31.4
these are what I came up so far, but it only delete the int patients, I don't know what to do next to delete both int and cnt to merge in one table.
data int;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
101 int 34.5 33.8 31.1
102 int 30.7 29.6 27.3
103 int 32.0 30.7 27.5
105 int 34.6 33.5 33.3
106 int 37.6 34.9 30.1
107 int 30.2 29.2 28.7
108 int 37.2 36.0 35.1
109 int 35.2 33.3 33.7
111 int 32.3 31.4 29.4
;
data cnt;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
401 cnt 33.7 33.4 33.2
402 cnt 31.2 30.1 29.8
404 cnt 30.8 31.1 31.8
406 cnt 29.2 29.0 28.9
408 cnt 27.7 27.3 27.9
409 cnt 33.8 32.9 31.4
;
data concat;
set int cnt;
BMI_change=BMI_9mos-BMI_base;
if BMI_change>-3 then delete;
run;
proc print noobs;
run;
Please post your code in a code block.
data concat;
set int cnt;
BMI_change=BMI_9mos-BMI_base;
if group = 'int' and BMI_change>-3 then delete;
else if group = 'cnt' and BMI_change ... then delete;
run;
proc print noobs;
run;
also the control group patients whose BMI increased over time.
You need to first add conditional logic, so that it does different logic for each group. Then you need to convert the criteria above to code, increased over time means what in terms of the difference??
I'll let you convert that logic to SAS code by filling in the ... in the code above.
@NhatHoang1 wrote:
these are what I came up so far, but it only delete the int patients, I don't know what to do next to delete both int and cnt to merge in one table.
data int;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
101 int 34.5 33.8 31.1
102 int 30.7 29.6 27.3
103 int 32.0 30.7 27.5
105 int 34.6 33.5 33.3
106 int 37.6 34.9 30.1
107 int 30.2 29.2 28.7
108 int 37.2 36.0 35.1
109 int 35.2 33.3 33.7
111 int 32.3 31.4 29.4
;
data cnt;
input ID$ GROUP$ BMI_base BMI_3mos BMI_9mos;
cards;
401 cnt 33.7 33.4 33.2
402 cnt 31.2 30.1 29.8
404 cnt 30.8 31.1 31.8
406 cnt 29.2 29.0 28.9
408 cnt 27.7 27.3 27.9
409 cnt 33.8 32.9 31.4
;
data concat;
set int cnt;
BMI_change=BMI_9mos-BMI_base;
if BMI_change>-3 then delete;
run;
proc print noobs;
run;
data int_cnt;
set int cnt;
*derive new variable;
bmi_change=bmi_9mos-bmi_base;
if group='int' then do;
if bmi_change >-3 and bmi_change <0 then delete;
end;
if group='cnt' then do;
if bmi_change>0 then delete;
end;
run;
proc print data=int_cnt;
run;
I think it would be better for you to put bmi_change < 0 for the first condition. In this data, you did not have any that were no change, but technically a decrease would have to be a negative value in bmi_change. Also, increase means bmi_change would be > 0. 0 would represent no change.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.