BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DShah
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

4 REPLIES 4
mkeintz
PROC Star
  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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
DShah
Fluorite | Level 6

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

mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
DShah
Fluorite | Level 6

Hi Mkeintz

This is what i wanted. Thank you so much.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1181 views
  • 1 like
  • 2 in conversation