I am trying to capture a phrase from my dataset that includes a bunch of terms. I am using PROC SQL to get the list of variables separated by a comma. I need to use this phrase in a SAS function with IN: (which I believe finds instances that carry the relevant string). But the code gives me 0 observations despite having variables in my data.
SAS DATA STEP:
proc sql noprint;
select upcase("'"||STRIP(toxxx)||"'") into:neurolist separated by ', '
from test;quit;
%put &neurolist;
LOG:
Macro variable NEUROLIST resolves to 'CONFUSION', 'DIZZINESS', 'HEADACHE', 'INSOMNIA', 'MEMORY IMPAIRMENT', 'TREMOR'
6767 %put &neurolist;
'CONFUSION', 'DIZZINESS', 'HEADACHE', 'INSOMNIA', 'MEMORY IMPAIRMENT', 'TREMOR'.
The codes doesn't get me an error. It works, but doesn't have any observations.
NOTE: There were 227 observations read from the data set WORK.MEDS_NEURO.
NOTE: The data set WORK.NEURODEX has 0 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.03 seconds
Please see attachment for my dataset that has the term "HEADACHE", but my code doesn't capture it. Any idea why?
Your values have to exactly match how they exists in the dataset ie. HEADACHE is not equal to NEUROTOXICITY(HEADACHE).
So you may have to use index() or find() or prxmatch() to find a word in a string.
proc sql noprint;
select STRIP(toxxx) into:neurolist separated by '|'
from test;quit;
%put &neurolist;
proc sql;
create table neurodex as
select a.*, b.toxxx
from meds_neuro as a, test as b
where prxmatch("m/&neurolist/io",a.cmindco)>0;
quit;
You've shown the log from the part of the program that works. That's a good start.
If you want help in debugging the program, you will need to show the log from the part of the program that doesn't work.
@saslove wrote:
As I had mentioned in the post , the program executed but gave me no observations. Log is clear.
You didn't show any code and there's no attachment. You're probably doing something wrong but since we can't see the code, data or log your guess is as good as ours at the moment.
Where is the data step code? Also show examples of the data you are searching.
Make sure to use the Insert Code or Insert SAS Code icons on the menu to open a pop-window to enter your text so that formatting is preserved.
I think you don't need the macro variable at all. Please try:
proc sql;
create table neurodex as
select a.*, b.toxxx
from meds_neuro as a, test as b
where a.cmindco contains upcase(strip(b.toxxx));
quit;
Your values have to exactly match how they exists in the dataset ie. HEADACHE is not equal to NEUROTOXICITY(HEADACHE).
So you may have to use index() or find() or prxmatch() to find a word in a string.
proc sql noprint;
select STRIP(toxxx) into:neurolist separated by '|'
from test;quit;
%put &neurolist;
proc sql;
create table neurodex as
select a.*, b.toxxx
from meds_neuro as a, test as b
where prxmatch("m/&neurolist/io",a.cmindco)>0;
quit;
This works perfectly! Thank you SuryaKiran!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.