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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 493 views
  • 0 likes
  • 2 in conversation