BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mrcodes
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
mrcodes
Calcite | Level 5
Try this. It looks like when i copied pasted it removed one of the spaces between drug1 and drug2 in the cards.

data example;
input drug1 :& $30. drug2 $30.;
cards;
thc cannabinoids
cannabinoids thc/carboxy-thc
carboxy-thc cannabinoids
;
run;
mrcodes
Calcite | Level 5
It keeps deleting the second space between drug1 and drug2 in the cards.. should be two spaces when you enter it into SAS
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
mrcodes
Calcite | Level 5
Yes! It looks like the updated code did work! Thank you!

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