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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.