I have 70 variables are pre-test and another 70 variables are post-test. I am going to do the two-sample Wilcoxon test., but how do I format these variable so I will have a new variable called "time" that tells SAS the timepoint: pre=1 and post=2 for each pair?
70 Pre-test variables:
PRETC1 |
PRETC2 |
PRETC3 |
PRETC4 |
PRETC5 |
PRETC6 |
PRETC7 |
PREEBC1 |
PREEBC2 |
PREEBC3 |
PREEBC4 |
PREEBC5 |
PREEBC6 |
PREEBC7 |
PREEBC8 |
PREEBC9 |
PREEBC10 |
PREEBC11 |
PRETOP1 |
PRETOP2 |
PRETOP3 |
PRETOP4 |
PRETOP5 |
PRETOP6 |
PRETOP7 |
PRETOP8 |
PRETOP9 |
PRETOP10 |
PRETOP11 |
PRETOP12 |
PRETOP13 |
PRETOP14 |
PRETOP15 |
PRETOP16 |
PRETOP17 |
PRETOP18 |
PRETOP19 |
PRETOP20 |
PRETOP21 |
PREMENT |
PREMENTRANK1 |
PREMENTRANK2 |
PREMENTRANK3 |
PREMENTRANK4 |
PREMENTRANK5 |
PREMENTRANK6 |
PREMENTRANK7 |
PREMENTRANK8 |
PREMENTRANK9 |
PREMENTRANK10 |
PREMENTRANK11 |
PREMENTRANK12 |
PREMENTRANK13 |
PREMENTRANK14 |
PREMENTRANK15 |
PREMENTRANK16 |
PREMENTRANK17 |
PREMENTRANK18 |
PREMENTRANK18SPECIFY |
PREMENTRANK19 |
70 Post-test variables:
POSTTC1 |
POSTTC2 |
POSTTC3 |
POSTTC4 |
POSTTC5 |
POSTTC6 |
POSTTC7 |
POSTEBC1 |
POSTEBC2 |
POSTEBC3 |
POSTEBC4 |
POSTEBC5 |
POSTEBC6 |
POSTEBC7 |
POSTEBC8 |
POSTEBC9 |
POSTEBC10 |
POSTEBC11 |
POSTTOP1 |
POSTTOP2 |
POSTTOP3 |
POSTTOP4 |
POSTTOP5 |
POSTTOP6 |
POSTTOP7 |
POSTTOP8 |
POSTTOP9 |
POSTTOP10 |
POSTTOP11 |
POSTTOP12 |
POSTTOP13 |
POSTTOP14 |
POSTTOP15 |
POSTTOP16 |
POSTTOP17 |
POSTTOP18 |
POSTTOP19 |
POSTTOP20 |
POSTTOP21 |
POSTMENT |
POSTMENTRANK1 |
POSTMENTRANK2 |
POSTMENTRANK3 |
POSTMENTRANK4 |
POSTMENTRANK5 |
POSTMENTRANK6 |
POSTMENTRANK7 |
POSTMENTRANK8 |
POSTMENTRANK9 |
POSTMENTRANK10 |
POSTMENTRANK11 |
POSTMENTRANK12 |
POSTMENTRANK13 |
POSTMENTRANK14 |
POSTMENTRANK15 |
POSTMENTRANK16 |
POSTMENTRANK17 |
POSTMENTRANK18 |
POSTMENTRANK18SPECIFY |
POSTMENTRANK19 |
You may find reformatting the data to
When C1 C2 C3 ... EBC1 EBC2 EBC3 ...Top1 Top2 Top3 ...
where the first variable indicates Pre Or Post, such as 1 for Pre and 2 for Post.
Then your test would look like:
proc npar1way data=have wilcoxon correct=no data=React; class When; var C1; exact wilcoxon; run;
Yes, I understand that I need a variable indicating the timepoint (pre or post). But I don't know how to reformat the data. Should I use transpose or anything?
@Denali wrote:
Yes, I understand that I need a variable indicating the timepoint (pre or post). But I don't know how to reformat the data. Should I use transpose or anything?
This is one way to transpose the data:
data want; set have; When = 1; C1=PRETC1; C2=PRETC2; C3=PRETC3; C4=PRETC4; C5=PRETC5; C6=PRETC6; C7=PRETC7; /*all the other PRE variables go here*/ output; When = 2; C1=POSTTC1; C2=POSTTC2; C3=POSTTC3; C4=POSTTC4; C5=POSTTC5; C6=POSTTC6; C7=POSTTC7; /*all the other POST variables go here*/ output; keep when C1 - C7 /*and the other new variables from the left of the = signs*/ run;
Careful use of arrays would shorten the code but I'll leave that as an exercise for the interested reader. Doing something like this by hand is good incentive to learn arrays.
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.
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.