I am working on a clinical trial with 2310 subjects where I have to randomize treatments. The randomization consists of one factor(fac) "Age" where the categories are "1" if >18 and" 2" if 6 to <18 and "3" if <6. The treatments are A, B,C. The initial enrollment for each subject is defined as Xjk where K is the treatment(A, B, C) and j is the age factor(1,2,3). So you would have XjA, XjB and Xjc possibilities for each subject. The initial data looks like this:
Subject Fac X Treatment
1 2 XjA A
2 1 XjB B
3 2 XjC C
4 3 XjA A
........
2310 1 XjC A
I need to design a variable(Mjk) that's going to count the updated allocation if a new subject with a different j value is going to come in, for example M11 would be where age factor=1(j) and treatment=1(k) for the particular subject, M12 would be age factor=1 and treatment=2 for that subject, so I need to check within each subject and I am not sure how to do that. I am very new to SAS so I don't know how to design this in loops, I initially did an if/else statement but this was not accounting for each new subject. The initial code is shown below:
data m12;
set data;
if fac1="1" then do;
if X="XjB" and t="2" then M="M12";
data m13;
set data;
if fac1="1" then do;
if X="Xjc" and t="3" then m="m13";
end;
run;
Any help at all would be greatly appreciated! Thank you.
Sorry your question is unclear.
What's the output you expect for the example you provided?
Hi, I am sorry here is an updated question:
The variable Mjk is going to look at the X variable and the fac variable for each subject and update the allocation based on each subject.
So the data set should look like this:
Subject Fac X Treatment M
1 2 XjA A M2A
2 1 XjB B M1B
3 2 XjC C M2C
4 3 XjA A M3A
........
2310 1 XjC A M1A
Yes but how would I check for the "fac" of each subject within the data set? The variable M should update after each subject.
The data step executes for each observation. This works:
data m12;
set data;
M = catt('M', FAC, TREATMENT);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.