<?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 Re: how to write out the message regarding mismatch variable in the log and abort from the macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552378#M153547</link>
    <description>&lt;P&gt;The PUTLOG statement will write messages in the log:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n05jha8tsrpanyn19m05ss7ltv6e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n05jha8tsrpanyn19m05ss7ltv6e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ABORT statement will end your SAS session:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p0hp2evpgqvfsfn1u223hh9ubv3g.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p0hp2evpgqvfsfn1u223hh9ubv3g.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Apr 2019 00:45:22 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2019-04-19T00:45:22Z</dc:date>
    <item>
      <title>how to write out the message regarding mismatch variable in the log and abort from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552325#M153526</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you please let me know the way to write out an error or warning message along with the name given in the varlist which is not in the input dataset. For example, %varlist= a b c d; and variable d is not in the input 'CLASS' dataset&lt;/P&gt;&lt;P&gt;I would like to the display in the log the following message after running names1 datasets.&lt;/P&gt;&lt;P&gt;'Variable 'D'&amp;nbsp; is not in the CLASS dataset.'&lt;/P&gt;&lt;P&gt;or if variable D and C are not in the class dataset then the message 'Variable C and D are not in the CLASS dataset.'&lt;/P&gt;&lt;P&gt;And after that system should abort or go to the end instead running next data step.&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let varlist= a b c d;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;%let&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt; varlist_quotesAndcomma&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"%sysfunc(prxchange(s/\s+/%nrbquote("&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;")/i,-1,&amp;amp;varlist))"&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt; &amp;nbsp;&lt;SPAN&gt;%put&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;=&lt;/SPAN&gt;varlist_quotesAndcomma&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;DATA checkdata;&lt;/P&gt;&lt;P&gt;%DO&amp;nbsp;_t =&amp;nbsp;&lt;STRONG&gt;1&lt;/STRONG&gt;&amp;nbsp;%TO&amp;nbsp;%sysfunc(countw("&amp;amp;varlist",' '));&lt;/P&gt;&lt;P&gt;name = strip(scan("&amp;amp;&amp;amp;varlist",&amp;amp;_t," "));&lt;/P&gt;&lt;P&gt;OUTPUT;&lt;/P&gt;&lt;P&gt;%END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;data names (keep=name);&lt;/P&gt;&lt;P&gt;set dictionary&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;columns&lt;/SPAN&gt;( where =(&lt;SPAN&gt; libname&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;'SASHELP'&lt;/SPAN&gt; and memname&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;'CLASS'&lt;/SPAN&gt; and &lt;SPAN&gt;upcase&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;name&lt;SPAN&gt;)&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;%upcase&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;&amp;amp;&lt;/SPAN&gt;varlist_quotesAndcomma&lt;SPAN&gt;))));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data names1;&lt;/P&gt;&lt;P&gt;merge names(in=names) checkdata(in=checkdata);&lt;/P&gt;&lt;P&gt;if checkdata and not names;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 20:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552325#M153526</guid>
      <dc:creator>Sami1234</dc:creator>
      <dc:date>2019-04-18T20:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to write out the message regarding mismatch variable in the log and abort from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552378#M153547</link>
      <description>&lt;P&gt;The PUTLOG statement will write messages in the log:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n05jha8tsrpanyn19m05ss7ltv6e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n05jha8tsrpanyn19m05ss7ltv6e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ABORT statement will end your SAS session:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p0hp2evpgqvfsfn1u223hh9ubv3g.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p0hp2evpgqvfsfn1u223hh9ubv3g.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 00:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552378#M153547</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-04-19T00:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to write out the message regarding mismatch variable in the log and abort from the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552380#M153548</link>
      <description>&lt;P&gt;Here a coding option which should give you the idea.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varlist=name a sex c;

proc sql;
  create view v_columns as
  select upcase(name) as name
  from dictionary.columns
  where libname='SASHELP' and memname='CLASS'
  ;
quit;

data _null_;
  if 0 then set v_columns;
  dcl hash h1(dataset:'v_columns');
  h1.defineKey('name');
  h1.defineDone();
  do i=1 by 1;
    name=upcase(scan("&amp;amp;varlist",i,,'kn'));
    if missing(name) then leave;
    if h1.check() ne 0 then
      do;
        putlog 'WARNING: Variable ' name 'not in sashelp.class';
        MissVarFlg=1;
      end;
  end;
  if MissVarFlg=1 then
    do;
/*      some additional exception handling */
    end;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Apr 2019 02:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-out-the-message-regarding-mismatch-variable-in-the/m-p/552380#M153548</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-04-19T02:06:15Z</dc:date>
    </item>
  </channel>
</rss>

