BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ayin
Quartz | Level 8

 

/* sample dataset */
data have;
  infile datalines dlm=",";
  input date $ value;
datalines;
05AUG2010,5
;
run;


/* macro to calculate percentage */
%macro test11;
%global valueMax;
%let valueMAX = 10;

data WORK.have_adj;
set WORK.have;

format perc best8.;
perc = value/&valueMAX.;
run;

%mend test11;


/* macro to execute */
%let dataName = test;
%macro runTEST;

 %if %sysfunc(find("&dataName.",'test')) ge 1 %then %do;   /* something wrong here */
    %test11; 
    %end; 

%mend runTEST;
%runTEST;

/* check whether macro 'test' has been executed */
%put _ALL_;
run;

 

 The result suggests the macro 'test11' has not been executed. How to fix it?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Remove the quotes from the macro variable in the FIND function. 

Modified your code for testing to make it easier:

 

%macro runTEST(dataName);

 %if %sysfunc(find(&dataName.,test)) ge 1 %then %do;   /* something wrong here */
    %put FOUND TEST;
    %end; 
   %else %do;
   	%put NO TEST;
   %end;

%mend runTEST;
%runTEST(test);
%runTEST(hello_test123);
%runTEST(random);

View solution in original post

3 REPLIES 3
Reeza
Super User

Remove the quotes from the macro variable in the FIND function. 

Modified your code for testing to make it easier:

 

%macro runTEST(dataName);

 %if %sysfunc(find(&dataName.,test)) ge 1 %then %do;   /* something wrong here */
    %put FOUND TEST;
    %end; 
   %else %do;
   	%put NO TEST;
   %end;

%mend runTEST;
%runTEST(test);
%runTEST(hello_test123);
%runTEST(random);
ayin
Quartz | Level 8

Thank you @Reeza for both the answer and tips! That solves the problem. 

Ksharp
Super User
%macro runTEST(dataName);

 %if %index(&dataName.,test) %then %do;   /* something wrong here */
    %put FOUND TEST;
    %end; 
   %else %do;
   	%put NO TEST;
   %end;

%mend runTEST;
%runTEST(test)
%runTEST(hello_test123)
%runTEST(random)

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 24277 views
  • 2 likes
  • 3 in conversation