BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lone0708
Fluorite | Level 6

Hi All,

I want to calculate the mean of blood pressures in my dataset. I have a variables for each blood pressure (bp1, bp2,bp3 etc). It is variable how many blood pressure each participant have (they can have up to 20 or more). 

 

data have;

input ID bp1 bp2 bp 3;

datalines;

1 145 120 125

2 130 . . 

3 125 125

;

run;

 

data want;

input ID bp1 bp2 bp3 mean;

datalines;

1 145 120 125 130

2 130 . . 130

3 125 125 125

;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If all the variables share a common prefix like in your sample data, you can do this

 

data have;
input ID bp1 bp2 bp3;
datalines;
1 145 120 125 
2 130 .   .   
3 125 125 .   
;


data want;
   set have;
   mean = mean(of bp:);
run;

 

Result:

 

ID bp1 bp2 bp3 mean
1  145 120 125 130
2  130 .   .   130
3  125 125 .   125

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

If all the variables share a common prefix like in your sample data, you can do this

 

data have;
input ID bp1 bp2 bp3;
datalines;
1 145 120 125 
2 130 .   .   
3 125 125 .   
;


data want;
   set have;
   mean = mean(of bp:);
run;

 

Result:

 

ID bp1 bp2 bp3 mean
1  145 120 125 130
2  130 .   .   130
3  125 125 .   125
LinusH
Tourmaline | Level 20

The most straightforward way is to transpose your data so you have one row for each test. 

Then you can use a standard procedure to calculate the mean (PROC SQL, MEANS etc).

Data never sleeps

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 1535 views
  • 2 likes
  • 3 in conversation