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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.