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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: