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;

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