Hi,
I have two data sets. The first one contains a list of patient with a description of their medical condition. The second one contains a list of code associated with key word.
I removed spaces between words and put everything in capital letter to make data matching easier.
The data set "subject" contains description of medical condition looks like this (only one observation is shown but I have 20,000) :
ID | CONCLUSION |
1 | SIGNOFARRHYTMIA |
The data set "codes" contains codes associated with key word looks like this :
code | yes_a | yes_b | no_a |
1.5.1 | ARRHYTMIA | ARHYTMIA | NOSIGN |
I created a macro variable for every variable of the "codes" data set (see below)
data _null_;
set codes;
call symput("code",(code));
call symput("yes_a",(yes_a));
call symput("yes_b",(yes_b));
call symput("no_a",(no_a));
run;
After that, I told SAS "Look in the "conclusion" variable and if you can find the a match between the conclusion and the macro variable '&yes_a' then do a = 1" (see below).
data subject_match; set subject;
if find (conclusion, '&yes_a') then a = 1;
if find (conclusion, '&no_a') then z = 0;
run;
The problem is that this step doesn't work. I have no error code in the log but even if the words after in the string, "a" never equals to 1.
Can anyone help me with that?
Thank you in advance.
Thanks to each of you for your answers.
I figured the solution by myself. I only added the trim function before calling my macro variable.
data subject_match; set subject;
a = find(conclusion, trim("&yes_a");
z = find(conclusion, trim("&no_a");
run;
It worked perfectly as I wished.
Cheers
After this step
data _null_;
set codes;
call symput("code",(code));
call symput("yes_a",(yes_a));
call symput("yes_b",(yes_b));
call symput("no_a",(no_a));
end;
run;
only the data from the last observation in codes will be stored in the 4 macro variables.
Well, first off macro variables need to be in double quotes to dereference:
if find (conclusion, "&yes_a") then a = 1;
Secondly, always put the dot after macro variables, it is best practice as sometimes it will matter.
Third, coding is more complicated than just finding strings in other strings, there could be any number of connotations.
@dera wrote:
Hi,
I have two data sets. The first one contains a list of patient with a description of their medical condition. The second one contains a list of code associated with key word.
I removed spaces between words and put everything in capital letter to make data matching easier.
The data set "subject" contains description of medical condition looks like this (only one observation is shown but I have 20,000) :
ID CONCLUSION 1 SIGNOFARRHYTMIA
The data set "codes" contains codes associated with key word looks like this :
code yes_a yes_b no_a 1.5.1 ARRHYTMIA ARHYTMIA NOSIGN
I created a macro variable for every variable of the "codes" data set (see below)
data _null_; set codes; call symput("code",(code)); call symput("yes_a",(yes_a)); call symput("yes_b",(yes_b)); call symput("no_a",(no_a)); end; run;
After that, I told SAS "Look in the "conclusion" variable and if you can find the a match between the conclusion and the macro variable '&yes_a' then do a = 1" (see below).
data subject_match; set subject; if find (conclusion, '&yes_a') then a = 1; if find (conclusion, '&no_a') then z = 0; run;
The problem is that this step doesn't work. I have no error code in the log but even if the words after in the string, "a" never equals to 1.
Can anyone help me with that?
Thank you in advance.
Putting a bunch of values into macro variables is quite often the symptom of a not very well thought out process and often a misunderstanding of the macro processor. For example in this case the macro variable only contain the values from the last record of data set codes if that step executed at all. The "end" has no do so that given data _null_ step won't execute at all.
Second when wanting to use the value of a macro variable as text you use double quotes " such as "&yes_a." not the single quotes. Other wise the value would not resolve at all.
How many records are in your "codes" data set?
about 350 codes
Thanks to each of you for your answers.
I figured the solution by myself. I only added the trim function before calling my macro variable.
data subject_match; set subject;
a = find(conclusion, trim("&yes_a");
z = find(conclusion, trim("&no_a");
run;
It worked perfectly as I wished.
Cheers
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.