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;
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
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
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).
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.