Jack Smit
Jack Smit

Reputation: 3

Converting data set in SAS for 1-way anova

Essentially I need to reorder my data set.

The data consists of 4 columns, one for each treatment group. I'm trying to run a simple 1-way anova in SAS but I don't know how to reorder the data so that there are two columns, one with the responses and one with the treatments.

Here is some example code to create example data sets.

data have;
input A B C D;
cards;
26.72 37.42 11.23 44.33
28.58 56.46 29.63 76.86
29.71 51.91 . .
;
run;
data want;
input Response Treatment $;
cards;
26.72 A
28.58 A
29.71 A
37.42 B
56.46 B
51.91 B
11.23 C
29.63 C
44.33 D
76.86 D
;
run;

I'm sure this is a very simple solution but I didn't see the same thing asked elsewhere on the site. I'm typically an R user but have to use SAS for this analysis so I could be looking for the wrong keywords.

Upvotes: 0

Views: 90

Answers (2)

data _null_
data _null_

Reputation: 9109

If that is your data for which you must use SAS just read so that you get the structure required for ANOVA.

data have;
   do rep=1 to 3;
      do trt='A','B','C','D';
         input y @;
         output;
         end;
      end;
   cards;
26.72 37.42 11.23 44.33
28.58 56.46 29.63 76.86
29.71 51.91 . .
;;;;
   run;
proc print;
   run;

Upvotes: 0

Rhythm
Rhythm

Reputation: 682

I have used proc transpose for this, see below

/*1. create row numbers for each obs*/
data have1;
 set have;
 if _n_=1 then row=1;
 else row+1;
run;

proc sort data=have1; by row; run;

/*Transpose the dataset by row number*/
proc transpose data=have1 out=want0; 
by row;
run;

/*Final dataset by removing missing values*/
data want;
 set want0;
 drop row;
 if COL1=. then delete;
 rename _NAME_=Response
        COL1=Treatment;
run;    

proc sort data=want; by Response; run;

proc print data=want; run;

Upvotes: 0

Related Questions