BookmarkSubscribeRSS Feed
A_Train
Calcite | Level 5

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

3 REPLIES 3
Reeza
Super User

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?

Ksharp
Super User

&exemptarr,

Should be "a" "b" "c" "d" .......


and

if terms not in &exemptarr   -----> 

if terms not in ( &exemptarr )

data_null__
Jade | Level 19

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

  • exmp:;
  •    <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.

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

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