DATA Step, Macro, Functions and more

Add mean and %RSD at bottom of dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Add mean and %RSD at bottom of dataset

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


Accepted Solutions
Solution
‎05-25-2017 08:38 AM
Valued Guide
Posts: 797

Re: Add mean and %RSD at bottom of dataset

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;

View solution in original post


All Replies
Valued Guide
Posts: 797

Re: Add mean and %RSD at bottom of dataset

  1.  What is "% RSD"?
  2. Show us what the data looks like before processing
  3. Show us what you want the report to look like afterwards

 

Help us help you.

Occasional Contributor
Posts: 18

Re: Add mean and %RSD at bottom of dataset

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

Solution
‎05-25-2017 08:38 AM
Valued Guide
Posts: 797

Re: Add mean and %RSD at bottom of dataset

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;
Occasional Contributor
Posts: 18

Re: Add mean and %RSD at bottom of dataset

Hi Mkeintz

This is what i wanted. Thank you so much.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 130 views
  • 1 like
  • 2 in conversation