The SAS Output Delivery System and reporting techniques

How to print table into a different format?

Reply
Occasional Contributor
Posts: 14

How to print table into a different format?

[ Edited ]

Hello Sas community!

I'm doing some two way ANOVA on a dataset, it is a 3*3 table with 4 observations on each cell. But the original data is not that user-friendly.

 

Group Treatment SCORE
A 1 1.7
A 1 4.9
A 1 8.2
A 1 9.5
A 2 6.3
A 2 8.1
A 2 2
A 2 9.5
A 3 2.3
A 3 8.7
A 3 9.8
A 3 4.5
B 1 0.1
B 1 6.2
B 1 0.3
B 1 9.5
B 2 1.3

.......

C 3 8.5

 

 

I'm just wondering if I can print the dataset like this:

 QQ截图20160411102429.jpg 

 

Thanks so much!!

Super User
Posts: 19,815

Re: How to print table into a different format?

Posted in reply to joseph626

Interesting...not easily. Is there an alternate format that may get you close?

 

Super User
Super User
Posts: 7,961

Re: How to print table into a different format?

Posted in reply to joseph626

This assumes your data is sorted.  Basically I create an array, and using the treatment variable merge the rows up, and after two merges add an escape character newline in.  Once this is printed with ods escapechar set, it should be on a new line:

data have;
  input group $ treatment score;
datalines;
A 1 1.7
A 1 4.9
A 1 8.2
A 1 9.5
A 2 6.3
A 2 8.1
A 2 2
A 2 9.5
;
run;
data want;
  set have;
  by group treatment;
  array trt{3} $200;
  retain trt:;
  if first.treatment then trt{treatment}=put(score,3.1);
  else do;
    if countw(trt{treatment}," ")=2 then trt{treatment}=cats(trt{treatment},"^{newline}");
    trt{treatment}=catx(" ",trt{treatment},put(score,3.1));
  end;
  if last.group then output;
run;

ods escapechar="^";
proc report...;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 300 views
  • 1 like
  • 3 in conversation