I am trying to make an array to scan each row and remove 'cannabinoids' when 'thc' 'carboxy-thc' or 'thc/carboxy-thc' are present. An example of the data follows:
data example;
input drug1 :& $30. drug2 $30.;
cards;
thc cannabinoids
cannabinoids thc/carboxy-thc
carboxy-thc cannabinoids
;
run;
Here is the direction I was heading, but it does not seem to work.
data screen;
set alldrugs09;
array d{*} drug:;
do i=1 to dim(d);
if d{i} in ("thc/carboxy-thc" "thc" "carboxy-thc") then do;
if d{i}="cannabinoids" then d{i}="";
end;
end;
drop i;
run;
How about this:
data screen;
set example;
array d{*} drug:;
do i=1 to dim(d);
if d{i} in ("thc/carboxy-thc" "thc" "carboxy-thc") and whichc("cannabinoids",of d:) then do;
do j=1 to dim(d);
if d(j)="cannabinoids" then call missing(d(j));
end;
end;
end;
drop i j;
run;
data example;
input drug1 :& $30. drug2 $30.;
cards;
thc cannabinoids
cannabinoids thc/carboxy-thc
carboxy-thc cannabinoids
;
So you are expecting two different drug variables, DRUG1 and DRUG2, but your code as written does not produce two different drug values; DRUG2 is always missing. So this needs to be fixed. I can't debug the rest of your code until I have a working version of your data set.
How about this:
data screen;
set example;
array d{*} drug:;
do i=1 to dim(d);
if d{i} in ("thc/carboxy-thc" "thc" "carboxy-thc") and whichc("cannabinoids",of d:) then do;
do j=1 to dim(d);
if d(j)="cannabinoids" then call missing(d(j));
end;
end;
end;
drop i j;
run;
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.
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.
Ready to level-up your skills? Choose your own adventure.