DATA Step, Macro, Functions and more

Using a Macro Array as a Regular Array inside a data step

Reply
N/A
Posts: 1

Using a Macro Array as a Regular Array inside a data step

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

Super User
Posts: 17,868

Re: Using a Macro Array as a Regular Array inside a data step

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?

Super User
Posts: 9,682

Re: Using a Macro Array as a Regular Array inside a data step

&exemptarr,

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


and

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

if terms not in ( &exemptarr )

Respected Advisor
Posts: 3,777

Re: Using a Macro Array as a Regular Array inside a data step

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.

    Ask a Question
    Discussion stats
    • 3 replies
    • 692 views
    • 3 likes
    • 4 in conversation