BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ihtishamsultan
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

4 REPLIES 4
ballardw
Super User

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).

 

 

ihtishamsultan
Obsidian | Level 7

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.

 

PGStats
Opal | Level 21

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;
PG
Ksharp
Super User
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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 521 views
  • 0 likes
  • 4 in conversation