Hello,
I have variables Bp and Drug. I need to check what percentage of the patient have bp above 141 according to if they used a drug or not.
Data have;
input patientn bp drug$;
1 100 Yes
2 120 No
3 130 Yes
4 140 No
5 150 Yes
6 160 Yes
7 170 Yes
8 180 No
9 190 Yes
10 140 Yes
11 130 No
12 150 Yes
I want a table like this
Drug Ptcount Total Percent
Yes 5 8 62.5%
No 1 4 25%
Also, I would like to compare these percentages and see if they are statistically significantly different from each other.
Many thanks.
Start here
/* To get the table */
proc sql;
select
drug,
sum(bp>141) as ptCount,
count(bp) as total,
calculated ptCount / calculated total as percent format=percentn7.1
from have
group by drug;
quit;
/* to get tests */
data want;
set have;
if bp > 141 then highBp = "High"; else highBp = "Low";
run;
proc freq data=want;
tables drug*highBp / chisq noprint;
run;
What is PTCOUNT supposed to be?
Do you want a report that people read or a dataset?
How big is your actual data set? The tests for "significantly different" will likely be different if your sample is 12 records or 100 (or so).
ptcount =count of patientn where bp is >141.
I want a report that people can read.
I have about 600 values in the actual dataset but with the clause that comes down to 150.
Start here
/* To get the table */
proc sql;
select
drug,
sum(bp>141) as ptCount,
count(bp) as total,
calculated ptCount / calculated total as percent format=percentn7.1
from have
group by drug;
quit;
/* to get tests */
data want;
set have;
if bp > 141 then highBp = "High"; else highBp = "Low";
run;
proc freq data=want;
tables drug*highBp / chisq noprint;
run;
Data have;
input pid bp drug$;
cards;
1 100 Yes
2 120 No
3 130 Yes
4 140 No
5 150 Yes
6 160 Yes
7 170 Yes
8 180 No
9 190 Yes
10 140 Yes
11 130 No
12 150 Yes
;
proc sql;
select drug,count(distinct pid) as pcount,
(select count(distinct pid) from have where drug=a.drug) as total,
calculated pcount/calculated total as percent format=percent7.2
from have as a
where bp>140
group by drug;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.