I'm sure this is an easy solution, but I can't seem to find it online. I have created a macro array with a list of 100 or so words that I want excluded from various comments lines.
%array(&exemptarr, data=exemptvalues, var=exemptv);
data sasdata.commcheck;
set commentsearch;
i=0;
nomore=0;
format cleanname $100.;
do until (nomore);
i+1;
if scan(namelist, i, ' ') = ' ' then nomore=1;
else do;
terms = scan(namelist,i,' ');
if terms not in &exemptarr then cleanname=catx (' ', cleanname, terms);
end;
end;
run;
I would like to call the "exemptarr" array to compare it to the terms list but when I do without the ampersand it gives me the following:
ERROR: The right-hand operand must be an array name or a constant value list.
And when I include the ampersand(like in the example above) it gives me the following error:
WARNING: Apparent symbolic reference EXEMPTARR not resolved.
Any help would be much appreciated.
Thanks
What's in the %array code?
What happens if you try and resolve it before the code
%put &exemptarr;
And what does the log say if you run it with options mprint and mlogic turned on?
&exemptarr,
Should be "a" "b" "c" "d" .......
and
if terms not in &exemptarr ----->
if terms not in ( &exemptarr )
A-Train wrote:
I'm sure this is an easy solution, but I can't seem to find it online. I have created a macro array with a list of 100 or so words that I want excluded from various comments lines.
%array(&exemptarr, data=exemptvalues, var=exemptv);
data sasdata.commcheck;
set commentsearch;
i=0;
nomore=0;
format cleanname $100.;
do until (nomore);
i+1;
if scan(namelist, i, ' ') = ' ' then nomore=1;
else do;
terms = scan(namelist,i,' ');
if terms not in &exemptarrthen cleanname=catx (' ', cleanname, terms);
end;
end;
run;
I would like to call the "exemptarr" array to compare it to the terms list but when I do without the ampersand it gives me the following:
ERROR: The right-hand operand must be an array name or a constant value list.
And when I include the ampersand(like in the example above) it gives me the following error:
WARNING: Apparent symbolic reference EXEMPTARR not resolved.
Any help would be much appreciated.
Thanks
I would forget about taking your perfectly good SAS data set of exemptvalues and writing them to an enumerated list of macro variables. The data pretty much become useless at that point.
If I understand correctly you have a data set of text data (from various comment lines) in the variable "NAMELIST" and you want to remove any word in "NAMELIST" that is also in data exemptvalues. There are a number of way to do this include the way you are using. To create and ARRAY of exempvalues you could use PROC TRANSPOSE to transpose the data into a one observation data set and use that to create and array in a data step.
proc transpose data=sashelp.class out=exvalues prefix=exmp;
var name;
run;
data test;
if _n_ eq 1 then set exvalues;
array _ex
<the rest>
run;
How you remove the words depends on what you call a word and how they are delimited. It could be as simple as TRANSTRN but you should supply some sample data to make it easier to understand.
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.