BookmarkSubscribeRSS Feed
azt5173
Obsidian | Level 7

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. 

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

Sorry your question is unclear.

What's the output you expect for the example you provided?

azt5173
Obsidian | Level 7

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

ChrisNZ
Tourmaline | Level 20

Like this?

M = catt('M', FAC, TREATMENT);

 

azt5173
Obsidian | Level 7

Yes but how would I check for the "fac" of each subject within the data set? The variable M should update after each subject. 

ChrisNZ
Tourmaline | Level 20

The data step executes for each observation. This works:

 

data m12;
  set data;
  M = catt('M', FAC, TREATMENT);
run;
azt5173
Obsidian | Level 7
Okay, thank you I will try it.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1376 views
  • 1 like
  • 2 in conversation