BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

I am writing a macro of the form: 

%macro MacroCompareTables(base, compare, formatshort); 
	%if &formatshort NE 0 or &formatshort NE 1 %then %do; 
		%put ERROR: formathsort should be 1 (for short version) or 0 (for long version).;
	%end; 

	/* Here I would like to do validation on the tables base and compare provided. For example 
	if no libname assigned then it should be from work. If the tables not found in work, 
	I would like to tell the user that no such table available in the work. 
	Any suggestion on good things to do here?*/ 

	%if &formatshort = 1 %then %do; 
		proc compare briefsummary warning  base=&basem
	    compare=&comparem;
		run;
	%end; 
	%if &formatshort = 0 %then %do; 
		proc compare base=&basem
	    compare=&comparem;
		run;
	%end; 
%mend MacroCompareTables; 

Normally, I try to "control" (validate) for all possible misstakes i can come up with. One possible error in this macro is that the tables are not in the work library, any advice on how I could validate for this? 

2 REPLIES 2
andreas_lds
Jade | Level 19

Some ideas:

/* Assume &base is in work if &base does not contain a libref */
%if %index(&base., %str(.)) = 0 %then %do;
  /* no library specified in &base, prefix work */
  %let base = work.&base;
%end;

/* clone last block for &comapare */

/* no need for having proc compare twice in your code */
%local briefsummary;
%if &formatshort = 1 %then %do;
  %let briefsummary = briefsummary warning;
%end;

proc compare base=&base. compare=&compare &briefsummary;
run;

 

ChrisNZ
Tourmaline | Level 20

I don't understand why you worry about the work library. The table name in &base and &compare should include the library if needed.

Like this?

%macro MacroCompareTables(base, compare, formatshort); 
  %if &formatshort NE 0 and &formatshort NE 1 %then %do; 
    %put NOTE: Parameter formatshort not found and set to 0.;
    %let formatshort=0;
  %end;
  %if ^%sysfunc(exist(&base)) %then %do; 
    %put ERROR: Table &base not found.;
    %return;
  %end;
  %if ^%sysfunc(exist(&compare)) %then %do; 
    %put ERROR: Table &compare not found.;
    %return;
  %end;

  proc compare %if &formatshort %then briefsummary warning;
    base   =&basem
    compare=&comparem;
  run;

%mend MacroCompareTables; 

 

 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 394 views
  • 1 like
  • 3 in conversation