Avatar of labradorchik
labradorchik
Flag for United States of America asked on

How to call macro from one SAS program in another SAS program?

How can I call macro from one SAS program in another SAS program?

This is my SAS code with calling macro, which gets a warning "WARNING: Apparent symbolic reference MYMACRO not resolved."  
I thought this is a correct way to call macro. Anyone see a problem with the way I am calling my macro?

DATA testnbrs;
  INFILE 'phonenum.dat' TRUNCOVER;
    INPUT numbs $ 1-10 rcode $ 14-16;
RUN;

PROC PRINT DATA = testnbrs NOOBS;
  WHERE numbs = "&mymacro";
   TITLE "Testing ALL Phone Numbers";
RUN;

Open in new window



Below is the macro SAS code that I am trying to run:
%macro mymacro(numbs,rcode);
  if verify(trim(&numbs),"0123456789") > 0 then
    do;
      &numbs =" ";
      &rcode="1";
    end;

  else if length(trim(&numbs)) ^=10           then
    do;
      &numbs =" ";
      &rcode="1";
    end;

  else if length(substr(&numbs,1,10)) =10  then
    do;
      if verify(trim(&numbs),"0123456789") = 0 then
        do;
          &rcode="0";
        end;

if substr(&numbs,1,1) in ("0","1")        then
        do;
          &numbs =" ";
          &rcode="1";
        end;

      else if substr(&numbs,4,1) in ("0","1")   then
        do;
          &numbs =" ";
          &rcode="1";
        end;

      else if substr(&numbs,2,1)="9"            then
        do;
          &numbs =" ";
          &rcode="1";
        end;

   isame = 1;
      do i = 5 to 10;
        if substr(&numbs,4,1) not = substr(&numbs,i,1) then 
           isame = 0;
      end;

      if isame = 1 then
        do;
          &numbs =" ";
          &rcode="1";
        end;
    end;
%mend mymacro;

Open in new window


Input file phonenum.dat has the following numbers (for testing purposes):
012345678h
0123456789
9876543210
0987654321
0112345678
8876543210
DatabasesProgrammingUnix OS

Avatar of undefined
Last Comment
labradorchik

8/22/2022 - Mon
SOLUTION
Ian

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
labradorchik

ASKER
ShannonEE, thank you very much for your in-depth explanation!!
I can see where my problem was, but I am still getting the same error:

WARNING: Apparent invocation of macro NUMBERSTEST not resolved.

What I did I just run the SAS code that invokes the macro. I noticed that you run both (macro and the code which invokes macro in the same SAS program), but I need to keep them separated so this macro code can be invoked from any other programs as well. These have to be two different SAS programs. I assume that macro "numbersTest" would be a global variable and need to be available at any time I need to invoke it.  
How can I do that?
ASKER CERTIFIED SOLUTION
Ian

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ian

Slight typing error  (on last line)  "options" missing.

* specify FOLDER where you want to store all the macros */
/* *******    you fill in the dots *******      */
filename dateauto " ..... ";

/* make sure facility is turned on */
options mautosource;

/* access your date macros as well as SAS supplied macros */
options  sasautos=(dateauto sasautos);  

Open in new window

labradorchik

ASKER
Worked as a charm! :) I used %include statement. Thank you very much for all your comments!!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes