BookmarkSubscribeRSS Feed
joseph626
Obsidian | Level 7

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!!

2 REPLIES 2
Reeza
Super User

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

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1294 views
  • 1 like
  • 3 in conversation