Hello,
I would like to search 'ECZEMA' in the six columns from string1 to string6. Then I tried to run a do loop command. But an error message was shown in the log window. Please help, thank you.
data want; set have ; array string_{*} String1 - String6; do i = 1 to 6; if prxmatch('/ECZEMA/i',string_) then allergy=1; end; run;
The error messages were list below, and also why in the 'Note' statement, 'Numeric values have been converted to character values?'
ERROR: Illegal reference to the array string_.
NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
105:38 106:38 107:42 108:47 109:27 110:34 111:34 113:44
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.have may be incomplete. When this step was
stopped there were 0 observations and 18 variables.
WARNING: Data set WORK.have was not replaced because this step was
stopped.
You miss the index to array member.
May be next code will work
data want;
set have ;
array string_{*} String1 - String6;
do i = 1 to 6;
if prxmatch('/ECZEMA/i',string_(i)) then allergy=1;
end;
run;
You can try next code:
data want;
set have ;
array string_{*} String1 - String6;
do i = 1 to 6;
if upcase(string_(i)) = "ECZEMA" then allergy=1;
end;
run;
I have multiple prematching texts, which are not just 'ECZEMA,'
You miss the index to array member.
May be next code will work
data want;
set have ;
array string_{*} String1 - String6;
do i = 1 to 6;
if prxmatch('/ECZEMA/i',string_(i)) then allergy=1;
end;
run;
You forgot the index in your array reference
if prxmatch('/ECZEMA/i', string_{i}) then allergy = 1;
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.