SAS Procedures

Help using Base SAS procedures
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

%macro LOOP;
%do i=103 %to 103/*&runupto*/ ;
proc sql noprint;
select SYSTEM, FILENAME, TABLE_NAME, ATTRIBUTES, JOIN_TABLE, SECOND , AMOUNT, PROGRAM, LOOKUP
into :SYS, :FILE , :OUTTABLE, :FIELDS, :JOINTABLE, :JOINFIELD, :CADTOTAL, :CHECKER, :LOOK
from DATAVALIDATION where NUMBER=103;
QUIT;
%PUT &FIELDS;
data _NULL_;
if &CHECKER='PROGRAM_CHECK' THEN

CALL EXECUTE(%PROGRAM_CHECK(SYSTEMS=&SYS,FIRST=&FIELDS,SECOND=&JOINFIELD,BALANCE=&CADTOTAL,PARENTTABLE=&FILE,JOINTABLE=&JOINTABLE));
RUN;
/*proc append base=SOURCE data=TABLE2 FORCE;
RUN;*/
%END;

%mend;

ERROR OCCURED:Invalid macro name ;. It should be a valid SAS identifier no longer than 32 characters.
ERROR: A dummy macro will be compiled.


 

question: I have to run the macro( when the if condition is passed i have to run MACRO_CHECk)

can anyone tell me what is the error for it and what is the correct wat to write it

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

A couple of items for starters ...

 

Does the value of &CHECKER_PROGRAM really include single quotes?  

 

Trying to add CALL EXECUTE just complicates the program without adding any functionality.  You already have a macro running. Why not get rid of the DATA step entirely:

 

%if &CHECKER=PROGRAM_CHECK %THEN

%PROGRAM_CHECK(SYSTEMS=&SYS,FIRST=&FIELDS,SECOND=&JOINFIELD,BALANCE=&CADTOTAL,PARENTTABLE=&FILE,JOINTABLE=&JOINTABLE);

 

 

View solution in original post

4 REPLIES 4
Astounding
PROC Star

A couple of items for starters ...

 

Does the value of &CHECKER_PROGRAM really include single quotes?  

 

Trying to add CALL EXECUTE just complicates the program without adding any functionality.  You already have a macro running. Why not get rid of the DATA step entirely:

 

%if &CHECKER=PROGRAM_CHECK %THEN

%PROGRAM_CHECK(SYSTEMS=&SYS,FIRST=&FIELDS,SECOND=&JOINFIELD,BALANCE=&CADTOTAL,PARENTTABLE=&FILE,JOINTABLE=&JOINTABLE);

 

 

siddharthpeesary
Calcite | Level 5

Thank you so much you are a genius... actually in my table "PROGRAM_CHECK " is in character format so I thought  in if statement it should be in quotations(i.e %if &CHECKER= 'PROGRAM_CHECK' %THEN .....) but it executed when it is not in the Quotes ..

 If possible can you also tell me the reason ? 

 

Thanks again-:)

 

Astounding
PROC Star

DATA steps use quotes to compare strings, but macro language does not.  Here is a test you can run to become more famliar with the rules:

 

%macro test;

%let name=siddarth;

%if &name=siddarth %then %put Match #1;

%if &name='siddarth' %then %put Match #2;

%if '&name'='siddarth' %then %put Match #3;

%if "&name"="siddarth" %then %put Match #4;

%mend test;

%test

 

Of course, you can always invent a few more tests and experiment to become more familiar with the outcomes.

 

In the context of a DATA step, you would have to resolve macro variables and then understand what the DATA step looks like.  Resolving macro variables might generate:

 

if PROGRAM_CHECK = "PROGRAM_CHECK" then ..

if "PROGRAM_CHECK" = "PROGRAM_CHECK" then ...

if '&PROGRAM_CHECK" = 'PROGRAM_CHECK" then ...

 

The rules about using quotes or not all depend on whether the proper DATA step syntax would be expecting to see quotes at that point.

siddharthpeesary
Calcite | Level 5

Thank You I will try it -:)

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1599 views
  • 1 like
  • 2 in conversation