Hello everyone,
Currently I am struggling with a problem I cannot seem to resolve. I am trying to see the frequency that different antidepressants are appearing in the dataset along with if there are observations with more than one antidepressant. Every observation will have SubstanceName1-SubstanceName30 and Class1-Class30. Below is some sample data of how it appears in the set.
Sample Data
ID# SubstanceName1 SubstanceClass1 SubstanceName2 SubstanceClass2
1 Trazodone Antidepressant Fluoxetine Antidepressant
2 Heroin Opiate Trazodone Antidepressant
Currently the array code I am using below will only return the name of an antidepressant that appears last if there are multiple. Is there any way to count if there are observations with multiple antidepressants like the ID#1, and if so to return both Substance Names? Thank you for any guidance.
Data depress;
set set_1;
Array AntiD $ SubstanceClass1-SubstanceClass30;
Array Name $ SubstanceName1-SubstanceName30;
do i= 1 to 30;
if AntiD(i) = 'Antidepressant' then Depression = Name(i);
end;
run;
My mistake, how about this
Data depress;
set set_1;
Array AntiD $ SubstanceClass1-SubstanceClass30;
Array Name $ SubstanceName1-SubstanceName30;
count=0;
do i= 1 to 30;
if AntiD(i) = 'Antidepressant' then do;
Depression = Name(i);
count=count+1;
output;
end;
end;
run;
It seems like this will work:
Data depress;
set set_1;
Array AntiD $ SubstanceClass1-SubstanceClass30;
Array Name $ SubstanceName1-SubstanceName30;
count=0;
do i= 1 to 30;
if AntiD(i) = 'Antidepressant' then Depression = Name(i);
count=count+1;
output;
end;
run;
My mistake, how about this
Data depress;
set set_1;
Array AntiD $ SubstanceClass1-SubstanceClass30;
Array Name $ SubstanceName1-SubstanceName30;
count=0;
do i= 1 to 30;
if AntiD(i) = 'Antidepressant' then do;
Depression = Name(i);
count=count+1;
output;
end;
end;
run;
@dellerrrr wrote:
Paige Miller,
Awesome! Thank you. Do you have any thoughts on how to return those antidepressant names where there are multiple? I am trying to get a true measure of the distribution of them.
Thank you
I don't know what this means. Show me the exact output you want.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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: