Hi ,
My code wants to find whether string1(smq) is in the string2(AEDECOD) or not?
which doesn't work normally, why? how to change the code?
************smq list***********
SMQ
**bleep** fissure haemorrhage
**bleep** haemorrhage
**bleep** ulcer haemorrhage
Anastomotic haemorrhage
Anastomotic ulcer haemorrhage
......
;
**********what I have**********; data have; input subjid $ 1-7 aeseq 9 aestdtc $ 13-21 AEDECOD $ 25-57; cards; 01-004 1 2018/10/8 Anaemia 01-004 2 2018/10/8 Hyperkalaemia 01-004 3 2018/10/8 Peritoneal dialysis complication 01-006 1 2018/11/27 Blood phosphorus increased 01-007 1 2018/12/18 Faeces discoloured 01-016 1 2019/3/26 Diarrhoea 01-016 2 2019/3/29 Diarrhoea 01-018 1 2019/4/16 Arteriovenous fistula occlusion 01-018 2 2019/3/13 Faeces discoloured 01-018 3 2019/4/16 Hyperparathyroidism 01-018 4 2019/4/24 Rash 01-020 1 2019/3/19 Pruritus generalised 01-031 1 2019/6/13 Constipation 01-032 1 2019/7/20 Mouth ulceration 01-033 1 2019/8/12 Herpes zoster 01-037 1 2019/8/8 Vertigo 01-040 1 2019/8/9 Diarrhoea 01-040 2 2019/8/30 Insomnia 01-042 1 2019/9/11 Faeces discoloured 01-043 1 2019/9/11 Faeces discoloured ; run; ***here just list three kinds of smq to test the code; %let smq=**bleep** fissure haemorrhage/**bleep** haemorrhage/**bleep** ulcer haemorrhage/; ***find the smq in the AEDECOD; %macro find_smq(in, out); data &out; set ∈ if find("&smq",AEDECOD,"i") or index("&smq",AEDECOD) then AESIFL="Y"; if AESIFL="Y"; run; %mend; %find_smq(have, want);
please try the below code
**********what I have**********;
data have;
input subjid $ 1-7 aeseq 8 aestdtc $ 10-19 AEDECOD $ 20-57;
cards;
01-004 1 2018/10/8 Anaemia
01-004 2 2018/10/8 Hyperkalaemia
01-004 3 2018/10/8 Peritoneal dialysis complication
01-006 1 2018/11/27 Blood phosphorus increased
01-007 1 2018/12/18 Faeces discoloured
01-016 1 2019/3/26 Diarrhoea
01-016 2 2019/3/29 Diarrhoea
01-018 1 2019/4/16 Arteriovenous fistula occlusion
01-018 2 2019/3/13 Faeces discoloured
01-018 3 2019/4/16 Hyperparathyroidism
01-018 4 2019/4/24 Rash
01-020 1 2019/3/19 Pruritus generalised
01-031 1 2019/6/13 Constipation
01-032 1 2019/7/20 Mouth ulceration
01-033 1 2019/8/12 Herpes zoster
01-037 1 2019/8/8 Vertigo
01-040 1 2019/8/9 Diarrhoea
01-040 2 2019/8/30 Insomnia
01-042 1 2019/9/11 Faeces discoloured
01-043 1 2019/9/11 Faeces discoloured
;
run;
***here just list three kinds of smq to test the code;
%let smq=anal fissure haemorrhage|anal haemorrhage|Anal ulcer haemorrhage;
***find the smq in the AEDECOD;
%macro find_smq(in, out);
data &out;
set ∈
if prxmatch("m/&smq/oi",aedecod) then aesifl='Y';
if AESIFL="Y";
run;
%mend;
%find_smq(have, want);
garbage code displays above, update as following:
***here just list three kinds of smq to test the code;
%let smq=**bleep** fissure haemorrhage/**bleep** haemorrhage/**bleep** ulcer haemorrhage/;
Sorry, sensitive words, picture is here:
I'm afraid I'm having trouble understanding the problem, and what you are trying to do and what the desired results are. Could you take a simple example or two or three and show what the inputs are and what the desired output is?
please try the below code
**********what I have**********;
data have;
input subjid $ 1-7 aeseq 8 aestdtc $ 10-19 AEDECOD $ 20-57;
cards;
01-004 1 2018/10/8 Anaemia
01-004 2 2018/10/8 Hyperkalaemia
01-004 3 2018/10/8 Peritoneal dialysis complication
01-006 1 2018/11/27 Blood phosphorus increased
01-007 1 2018/12/18 Faeces discoloured
01-016 1 2019/3/26 Diarrhoea
01-016 2 2019/3/29 Diarrhoea
01-018 1 2019/4/16 Arteriovenous fistula occlusion
01-018 2 2019/3/13 Faeces discoloured
01-018 3 2019/4/16 Hyperparathyroidism
01-018 4 2019/4/24 Rash
01-020 1 2019/3/19 Pruritus generalised
01-031 1 2019/6/13 Constipation
01-032 1 2019/7/20 Mouth ulceration
01-033 1 2019/8/12 Herpes zoster
01-037 1 2019/8/8 Vertigo
01-040 1 2019/8/9 Diarrhoea
01-040 2 2019/8/30 Insomnia
01-042 1 2019/9/11 Faeces discoloured
01-043 1 2019/9/11 Faeces discoloured
;
run;
***here just list three kinds of smq to test the code;
%let smq=anal fissure haemorrhage|anal haemorrhage|Anal ulcer haemorrhage;
***find the smq in the AEDECOD;
%macro find_smq(in, out);
data &out;
set ∈
if prxmatch("m/&smq/oi",aedecod) then aesifl='Y';
if AESIFL="Y";
run;
%mend;
%find_smq(have, want);
at the moment since there are no matching values the macro returns a dataset with zero observations. so please update the macro variables values to below and run the macro so it returns a dataset with 4 observations.
%let smq=Anaemia|Diarrhoea|Insomnia;
There are a few different ways to do this and here is another way.
data smq;
infile cards truncover;
input smq $100.;
cards;
**bleep** fissure haemorrhage
**bleep** haemorrhage
**bleep** ulcer haemorrhage
Anastomotic haemorrhage
Anastomotic ulcer haemorrhage
Insomnia
run;
data have;
input subjid $ 1-7 aeseq 9 aestdtc $ 13-21 AEDECOD $ 25-57;
cards;
01-004 1 2018/10/8 Anaemia
01-004 2 2018/10/8 Hyperkalaemia
01-004 3 2018/10/8 Peritoneal dialysis complication
01-006 1 2018/11/27 Blood phosphorus increased
01-007 1 2018/12/18 Faeces discoloured
01-016 1 2019/3/26 Diarrhoea
01-016 2 2019/3/29 Diarrhoea
01-018 1 2019/4/16 Arteriovenous fistula occlusion
01-018 2 2019/3/13 Faeces discoloured
01-018 3 2019/4/16 Hyperparathyroidism
01-018 4 2019/4/24 Rash
01-020 1 2019/3/19 Pruritus generalised
01-031 1 2019/6/13 Constipation
01-032 1 2019/7/20 Mouth ulceration
01-033 1 2019/8/12 Herpes zoster
01-037 1 2019/8/8 Vertigo
01-040 1 2019/8/9 Diarrhoea
01-040 2 2019/8/30 Insomnia
01-042 1 2019/9/11 Faeces discoloured
01-043 1 2019/9/11 Faeces discoloured
;
run;
proc sql nolist;
select smq into :smq1-:smq999
from smq;
quit;
%let numsmqs=&sqlobs.;
%macro findem;
proc sql;
create table havesmqs as
select *
from have
where lowcase(aedecod) ? "%lowcase(&smq1.)"
%do i=1 %to &numsmqs.;
or lowcase(aedecod) ? "%lowcase(&&smq&i.)"
%end;
;quit;
%mend findem;
%findem;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.