<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Macro: Validation of libname in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772951#M245459</link>
    <description>&lt;P&gt;I am writing a macro of the form:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MacroCompareTables(base, compare, formatshort); 
	%if &amp;amp;formatshort NE 0 or &amp;amp;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 &amp;amp;formatshort = 1 %then %do; 
		proc compare briefsummary warning  base=&amp;amp;basem
	    compare=&amp;amp;comparem;
		run;
	%end; 
	%if &amp;amp;formatshort = 0 %then %do; 
		proc compare base=&amp;amp;basem
	    compare=&amp;amp;comparem;
		run;
	%end; 
%mend MacroCompareTables; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Oct 2021 07:56:57 GMT</pubDate>
    <dc:creator>SasStatistics</dc:creator>
    <dc:date>2021-10-08T07:56:57Z</dc:date>
    <item>
      <title>Macro: Validation of libname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772951#M245459</link>
      <description>&lt;P&gt;I am writing a macro of the form:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MacroCompareTables(base, compare, formatshort); 
	%if &amp;amp;formatshort NE 0 or &amp;amp;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 &amp;amp;formatshort = 1 %then %do; 
		proc compare briefsummary warning  base=&amp;amp;basem
	    compare=&amp;amp;comparem;
		run;
	%end; 
	%if &amp;amp;formatshort = 0 %then %do; 
		proc compare base=&amp;amp;basem
	    compare=&amp;amp;comparem;
		run;
	%end; 
%mend MacroCompareTables; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 07:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772951#M245459</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-10-08T07:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Validation of libname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772952#M245460</link>
      <description>&lt;P&gt;Some ideas:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Assume &amp;amp;base is in work if &amp;amp;base does not contain a libref */
%if %index(&amp;amp;base., %str(.)) = 0 %then %do;
  /* no library specified in &amp;amp;base, prefix work */
  %let base = work.&amp;amp;base;
%end;

/* clone last block for &amp;amp;comapare */

/* no need for having proc compare twice in your code */
%local briefsummary;
%if &amp;amp;formatshort = 1 %then %do;
  %let briefsummary = briefsummary warning;
%end;

proc compare base=&amp;amp;base. compare=&amp;amp;compare &amp;amp;briefsummary;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 08:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772952#M245460</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-08T08:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro: Validation of libname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772986#M245479</link>
      <description>&lt;P&gt;I don't understand why you worry about the work library. The table name in &amp;amp;base and &amp;amp;compare should include the library if needed.&lt;/P&gt;
&lt;P&gt;Like this?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%macro MacroCompareTables(base, compare, formatshort); 
  %if &amp;amp;formatshort NE 0 and &amp;amp;formatshort NE 1 %then %do; 
    %put NOTE: Parameter formatshort not found and set to 0.;
    %let formatshort=0;
  %end;
  %if ^%sysfunc(exist(&amp;amp;base)) %then %do; 
    %put ERROR: Table &amp;amp;base not found.;
    %return;
  %end;
  %if ^%sysfunc(exist(&amp;amp;compare)) %then %do; 
    %put ERROR: Table &amp;amp;compare not found.;
    %return;
  %end;

  proc compare %if &amp;amp;formatshort %then briefsummary warning;
    base   =&amp;amp;basem
    compare=&amp;amp;comparem;
  run;

%mend MacroCompareTables; &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 10:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-of-libname/m-p/772986#M245479</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-10-08T10:08:11Z</dc:date>
    </item>
  </channel>
</rss>

