BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
blueskyxyz
Lapis Lazuli | Level 10

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);

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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);
Thanks,
Jag

View solution in original post

8 REPLIES 8
blueskyxyz
Lapis Lazuli | Level 10

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/;

 

blueskyxyz
Lapis Lazuli | Level 10

Sorry, sensitive words, picture is here:

捕获.JPG

PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
Jagadishkatam
Amethyst | Level 16

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);
Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

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;

Thanks,
Jag
blueskyxyz
Lapis Lazuli | Level 10
Thanks @jag for your help.
BrianVarney
Fluorite | Level 6

 

 

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;

Brian Varney
Senior Technical Manager, Experis Solutions
269-365-1755 (c)
https://experis.solutions
www.experis.com
blueskyxyz
Lapis Lazuli | Level 10
 

@BrianVarney  Brain, thanks for your reply.

 

In my code, I also use the same mehod.捕获.JPG

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
  • 8 replies
  • 640 views
  • 3 likes
  • 4 in conversation