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

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

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