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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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