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:
Thanks so much!!
Interesting...not easily. Is there an alternate format that may get you close?
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.