BookmarkSubscribeRSS Feed
azt5173
Obsidian | Level 7

I am working on a clinical trial where I have to count the updated allocation of each treatments. There are 3 treatments(T)(1,2,3) and 3 age factors(J)(1,2,3). The current data set looks like this:

 

Subject   T     J

1             3    1 

2             2     2

3             1     3

4              5    1 

5              2     3

........................

2310        1      3

 

If J=1 and T=1 are equal to each other then Z11(variable for allocation) increases by 1

If J=1 and T=2  then Z12 count remains the same. 

if J=1 and T=3  then Z13 count remains the same. 

 

The above condition repeats for when J=2 and when J=3. And iterates each time a subject is added into the trial. 

 

So basically Zjt=count+1 if T=J and Zjt=count if T is not equal to Z. 

 

The dataset Z should look something like this 

Z11 Z12 Z13 Z21 Z22 Z23 Z31 Z32 Z33

6     1     4      7     5      9    10    15   12

 

I wrote the code below but it does not give me the result I want

 

 

data z;
set data;
array a z11-z13;
do i=1 to dim(a);
if t=1 and fac1=1 then z11=count+1;
else if t=2 and fac1=1 then z12=count;
else if t=3 and fac1=1 then z13=count;
end;
run;

 

Thank you for any help at all. 

 

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

And you want to use an array doing this or?

azt5173
Obsidian | Level 7

Array or anything useful that will help me do this. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 2 replies
  • 1226 views
  • 0 likes
  • 2 in conversation