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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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