Hi
I have a dataset with 6 columns. I wanted to add average and % RSD for all columns under the last value. is there a procedure to achieve this in SAS 9.4?
Thanks in advance
Not as neat as PROC REPORT, but it works:
data have;
input Code Slope50 Slope100 Slope150 Ratio50 Ratio100;
datalines;
1 386.99 915.65 2519.9 42.3 275.2
2 321.53 828.51 2753.8 38.8 332.4
3 311.81 946.18 2479.2 33.0 262.0
4 124.73 818.38 2528.7 15.2 309.0
5 275.85 925.42 2412.3 29.8 260.7
6 302.94 876.57 1301.0 34.6 148.4
run;
proc summary data=have;
var slope: ratio: ;
output out=stats1 (drop=_type_ _freq_) mean=;
output out=stats2 (drop=_type_ _freq_) cv=;
run;
data want;
set have stats1 (in=in1) stats2 (in=in2);
if in1 then txtcode='Average';
else if in2 then txtcode='CV';
else txtcode=put(code,7.);
run;
proc print data=want;
id txtcode;
var slope: ratio: ;
run;
Help us help you.
Hi Mkeintz
Thank you for your reply. % RSD is %CV (coefficient of Variance). Please find have and want datasets below. I want average and %CV calculated in the columns below those numbers:
Have:
Code | Slope50 | Slope100 | Slope150 | Ratio50 | Ratio100 |
1 | 386.99 | 915.65 | 2519.9 | 42.3 | 275.2 |
2 | 321.53 | 828.51 | 2753.8 | 38.8 | 332.4 |
3 | 311.81 | 946.18 | 2479.2 | 33.0 | 262.0 |
4 | 124.73 | 818.38 | 2528.7 | 15.2 | 309.0 |
5 | 275.85 | 925.42 | 2412.3 | 29.8 | 260.7 |
6 | 302.94 | 876.57 | 1301.0 | 34.6 | 148.4 |
want:
Code | Slope50 | Slope100 | Slope150 | Ratio50 | Ratio100 |
1 | 386.99 | 915.65 | 2519.9 | 42.3 | 275.2 |
2 | 321.53 | 828.51 | 2753.8 | 38.8 | 332.4 |
3 | 311.81 | 946.18 | 2479.2 | 33.0 | 262.0 |
4 | 124.73 | 818.38 | 2528.7 | 15.2 | 309.0 |
5 | 275.85 | 925.42 | 2412.3 | 29.8 | 260.7 |
6 | 302.94 | 876.57 | 1301.0 | 34.6 | 148.4 |
| Average | Average | Average | Average | Average |
| %CV | %CV | %CV | %CV | %CV |
Not as neat as PROC REPORT, but it works:
data have;
input Code Slope50 Slope100 Slope150 Ratio50 Ratio100;
datalines;
1 386.99 915.65 2519.9 42.3 275.2
2 321.53 828.51 2753.8 38.8 332.4
3 311.81 946.18 2479.2 33.0 262.0
4 124.73 818.38 2528.7 15.2 309.0
5 275.85 925.42 2412.3 29.8 260.7
6 302.94 876.57 1301.0 34.6 148.4
run;
proc summary data=have;
var slope: ratio: ;
output out=stats1 (drop=_type_ _freq_) mean=;
output out=stats2 (drop=_type_ _freq_) cv=;
run;
data want;
set have stats1 (in=in1) stats2 (in=in2);
if in1 then txtcode='Average';
else if in2 then txtcode='CV';
else txtcode=put(code,7.);
run;
proc print data=want;
id txtcode;
var slope: ratio: ;
run;
Hi Mkeintz
This is what i wanted. Thank you so much.
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: