<?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: Lost with macro calls in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183536#M34868</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would be helpful if you also list the macro &lt;EM&gt;Varexist&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Oct 2014 07:22:04 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2014-10-14T07:22:04Z</dc:date>
    <item>
      <title>Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183534#M34866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have several datasets, one for each geographical areas. What is a bit hard is that there are 96 areas, but for historical and administrative reasons, they are not indexed 01 to 96 but&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;01 02 ... 19 2A 2B 21 ...95&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then my datasets are indexed data_d01, data_d02, ... data_d19, data_d2a, data_d2b, data_d21, ... data_d95.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So what has been done until now and what I have trying to use is a table that has one variable, called &lt;EM&gt;dep2&lt;/EM&gt;, which takes these values 01 02 ... 19 2A 2B 21 ...95&lt;/P&gt;&lt;P&gt;Then the&amp;nbsp; way to do something for each dataset is to use the following lines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro MacroStandard(); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dep.dep2; /* table des (vrais) DEP reprise de RFL, POTE n'est plus par dir fiscale */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('d'!!left(_n_),dep2); /* la var contenant le code du DEP s'appelle dep2 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to 96 ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data temporary;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set data_d&amp;amp;&amp;amp;d&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend MacroStandard;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now what I wanted to do is for each of this dataset, check if one variable exists. So I have found a %Varexist(dataset, variable) macro, that perfectly works when I do&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put %Varexist(data_d01, myvar)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I want to do that for each area, so I have tried several combinations. I have now one that is working, but I definitely do not understand why at all, as it works since I have commentated a line to see what was happening, but does not work if I remove the line which is supposed not to be read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my program :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro TestDep (); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set dep.dep2;&lt;/P&gt;&lt;P&gt;call symput('d'!!left(_n_),dep2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to 96&lt;/P&gt;&lt;P&gt;%put d&amp;amp;&amp;amp;d&amp;amp;i;&lt;/P&gt;&lt;P&gt;*%put %VarExist(PotePrec.pote&amp;amp;anprec._d&amp;amp;&amp;amp;d&amp;amp;i,_1DX);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend TestDep;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%TestDep()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would gladly appreciate some help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT 1 : Add the macro varexist&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro VarExist(ds,var);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %local rc dsid result;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let dsid=%sysfunc(open(&amp;amp;ds));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var)) &amp;gt; 0 %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let result=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put NOTE: Var &amp;amp;var exists in &amp;amp;ds;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let result=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let rc=%sysfunc(close(&amp;amp;dsid));&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;amp;result&lt;/P&gt;&lt;P&gt;%mend VarExist;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183534#M34866</guid>
      <dc:creator>Aboiron</dc:creator>
      <dc:date>2014-10-14T07:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183535#M34867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543665.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543665.htm"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543665.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Comments of the * ...... ; form are still subject to macro processing.&lt;/P&gt;&lt;P&gt;Your line causes the varexist macro to be compiled&amp;amp;executed. Only /* ....&amp;nbsp; */ prevents macro execution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183535#M34867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-10-14T07:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183536#M34868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would be helpful if you also list the macro &lt;EM&gt;Varexist&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183536#M34868</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-10-14T07:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183537#M34869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not use the sashelp.vmembers access as being the same as some dictionary te quest? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183537#M34869</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-10-14T07:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183538#M34870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That explains a lot thx, but not everything.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So my macro works as it is written, and works when the &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;*%put %VarExist(PotePrec.pote&amp;amp;anprec._d&amp;amp;&amp;amp;d&amp;amp;i,_1DX); is not preceded by a *&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it does not work if I remove the previous %put line, and I do not understand why, as I assume -probably wrongly- it only does something external to the program&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183538#M34870</guid>
      <dc:creator>Aboiron</dc:creator>
      <dc:date>2014-10-14T07:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183539#M34871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would say for two very bad reasons &lt;/P&gt;&lt;P&gt;1. I have just arrived at my job and I tend to do thnigs the same way it has been done instead of recreating all myself&lt;/P&gt;&lt;P&gt;2. because I have a lot of trouble understanding your answer after "Why not use" (Im working a bit on that one)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183539#M34871</guid>
      <dc:creator>Aboiron</dc:creator>
      <dc:date>2014-10-14T07:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183540#M34872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Added&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183540#M34872</guid>
      <dc:creator>Aboiron</dc:creator>
      <dc:date>2014-10-14T07:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183541#M34873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The %do i = 1 %to 96 misses the semicolon.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183541#M34873</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-10-14T07:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183542#M34874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sashelp.vmember is a dynamic view that contains metadata about all datasets in all currently assigned libraries.&lt;/P&gt;&lt;P&gt;sashelp.vcolumn does the same for all columns in all tables in all currently assigned libraries.&lt;/P&gt;&lt;P&gt;Very useful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 07:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183542#M34874</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-10-14T07:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183543#M34875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well I am a bit confused, but thanks a lot, with your two answers I am now able to work appeased&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 08:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183543#M34875</guid>
      <dc:creator>Aboiron</dc:creator>
      <dc:date>2014-10-14T08:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183544#M34876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're not alone; I had lots of confusion grasping the concepts of the macro processor. Sometimes I still have.&lt;/P&gt;&lt;P&gt;Not that much different from the C preprocessor or similar tools.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 08:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183544#M34876</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-10-14T08:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Lost with macro calls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183545#M34877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Kurt even after many years I still having surprise with that macro environment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aboiron the set statement for concat all sasdatasets could be coded easier.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The set statement is supporting dataset lists. &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/documentation/cdl/en/lestmtsref/67407/HTML/default/viewer.htm#p00hxg3x8lwivcn1f0e9axziw57y.htm"&gt;http://support.sas.com/documentation/cdl/en/lestmtsref/67407/HTML/default/viewer.htm#p00hxg3x8lwivcn1f0e9axziw57y.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You could code the range or as a abbreviation using :&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 06:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lost-with-macro-calls/m-p/183545#M34877</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-10-15T06:24:42Z</dc:date>
    </item>
  </channel>
</rss>

