SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Appelsap
Calcite | Level 5

hi,

 

I have a question about the use of prxmatch and arrays.

I have a list with multiple different therapies (treat1-treat15). I want to select all chemotherapies from this list and combine different types of chemo that are given as combination therapy. I wrote the syntax below. This works for comparing treat{i} and treat{i+1}, but I also want to compare treat{i} with treat{i+2}, treat{i+3} etc. And preferably also compare treat{i} with treat{i+1} and treat {i+3} at the same time, as there might be up to three or four chemotherapies that need to be combined. Is there an easy way to do this? 

 

%let chemo = XY40|BC50|XA60|ZL90|OX15|MZ78;

 

data twee;
set een;

array treat15} $ treat1 - treat15;
array treat_dat{15} treat_dat1 - treat_dat15;

array CT{15}   CT1-CT15;

array CT_dat{15} CT_dat1-CT_dat15;

CT=0;

do i=1 to 15;

 

if prxmatch("m/&chemo/i", treat{i})>0 and prxmatch("m/&chemo/i", treat{i+1})>0

and treat_dat{i}=treat_dat{i+1} then do;

if treat{i}=XY40 and treat{i+1}=BC50 then do; CT{i}=OX15; CT_dat{i}=treat_dat{i}; end;

if treat{i}=XY40 and treat{i+1}=XA60 then do; CT{i}=MZ78; CT_dat{i}=treat_dat{i}; end;

end;

run;

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Without sample data it is hard to get a sense of what you are doing.

 

But it sounds like you just need another DO loop.

DO I=1 to 15 ;
  DO J=I+1 to 15;

Now you can compare the Ith variable in the array to the Jth variable in the array.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Without sample data it is hard to get a sense of what you are doing.

 

But it sounds like you just need another DO loop.

DO I=1 to 15 ;
  DO J=I+1 to 15;

Now you can compare the Ith variable in the array to the Jth variable in the array.

ballardw
Super User

You likely will need a much larger OUTPUT array. Consider comparing 4 items:

A B C D

The pairwise comparisons are

AB AC AD BC BD CD

 

The function comb will give the number of elements you may need:

data example;
   needed = comb(15,2);
run;

which will yield 105 combinations taken 2 at a time. Do you need to consider 3 at a time? That would be 455.

And if the ORDER encountered is important, where AB is different from BA in my starting discussion, then you need Permutations with the function Perm to get the number of permutations (210 for 15 taken 2 at time).

 

Your comparisons also will fail. To compare values:if treat{i}=XY40 is going to look for a variable named XY40. You should be using quoted literal values:

if treat{i}="XY40" 

 

You might want to look at the combinatorial functions ALLCOMB or Call Allcomb.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 1040 views
  • 0 likes
  • 3 in conversation