<?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 Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478505#M286367</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create macro variable which will have string as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"%varexist(sdtmcro.&amp;amp;dsn,var1) and %varexist(sdtmcro.&amp;amp;dsn,var2)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;: %varexist is macro in my directory which finds if variable exist in specified dataset. Var1 and var2 are present in another macro varibale "&amp;amp;variables" macro variable.&lt;/P&gt;&lt;P&gt;e.g. %put &amp;amp;variables= &amp;amp;dsn.var1, &amp;amp;dsn.var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to get above mentioned string, I am creating variable varcond like below for each variables and then concatenating them together :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _temp_;&lt;BR /&gt;%do i =1 %to %sysfunc(countw(&amp;amp;variables.));&lt;BR /&gt;%let var=%scan(&amp;amp;variables.,&amp;amp;i);&lt;BR /&gt;varcond= "%"||"varexist(sdtmcro.&amp;amp;dsn,&amp;amp;var)";&lt;BR /&gt;output;&lt;BR /&gt;%end;&lt;BR /&gt;domain="&amp;amp;dsn";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=_temp_;&lt;BR /&gt;by domain ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _temp_;&lt;BR /&gt;length varcondn $500.;&lt;BR /&gt;do until(last.domain );&lt;BR /&gt;set _temp_;&lt;BR /&gt;by domain ;&lt;BR /&gt;condn=catx(' and ',cond,varcond);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select condn into :&amp;nbsp;condition&lt;BR /&gt;from _temp_;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;condition;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;condition gets resolved string "1 and 1" instead of "&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var1&lt;/SPAN&gt;&lt;SPAN&gt;) and %varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var2&lt;/SPAN&gt;&lt;SPAN&gt;)".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest me solution on not resolve macro %varexist in macro variable &amp;amp;condition?&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jul 2018 22:12:08 GMT</pubDate>
    <dc:creator>petlove</dc:creator>
    <dc:date>2018-07-16T22:12:08Z</dc:date>
    <item>
      <title>Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478505#M286367</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create macro variable which will have string as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"%varexist(sdtmcro.&amp;amp;dsn,var1) and %varexist(sdtmcro.&amp;amp;dsn,var2)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;: %varexist is macro in my directory which finds if variable exist in specified dataset. Var1 and var2 are present in another macro varibale "&amp;amp;variables" macro variable.&lt;/P&gt;&lt;P&gt;e.g. %put &amp;amp;variables= &amp;amp;dsn.var1, &amp;amp;dsn.var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to get above mentioned string, I am creating variable varcond like below for each variables and then concatenating them together :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _temp_;&lt;BR /&gt;%do i =1 %to %sysfunc(countw(&amp;amp;variables.));&lt;BR /&gt;%let var=%scan(&amp;amp;variables.,&amp;amp;i);&lt;BR /&gt;varcond= "%"||"varexist(sdtmcro.&amp;amp;dsn,&amp;amp;var)";&lt;BR /&gt;output;&lt;BR /&gt;%end;&lt;BR /&gt;domain="&amp;amp;dsn";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=_temp_;&lt;BR /&gt;by domain ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _temp_;&lt;BR /&gt;length varcondn $500.;&lt;BR /&gt;do until(last.domain );&lt;BR /&gt;set _temp_;&lt;BR /&gt;by domain ;&lt;BR /&gt;condn=catx(' and ',cond,varcond);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select condn into :&amp;nbsp;condition&lt;BR /&gt;from _temp_;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;condition;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;condition gets resolved string "1 and 1" instead of "&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var1&lt;/SPAN&gt;&lt;SPAN&gt;) and %varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var2&lt;/SPAN&gt;&lt;SPAN&gt;)".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest me solution on not resolve macro %varexist in macro variable &amp;amp;condition?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478505#M286367</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-16T22:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478506#M286368</link>
      <description>&lt;P&gt;Re-run your code, but first issue the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, show us the SASLOG so we can see the error.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478506#M286368</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-16T22:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478508#M286369</link>
      <description>&lt;P&gt;There is no error in log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am expecting to get &amp;amp;condition resolved to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"%varexist(sdtmcro.&amp;amp;dsn,var1) and %varexist(sdtmcro.&amp;amp;dsn,var2)"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But, it is getting resolved to :&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"1 and 1"&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478508#M286369</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-16T22:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478509#M286370</link>
      <description>&lt;P&gt;How can we possibly help, if you won't show us the SASLOG, and we don't have the code to see what %varexist does?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run the code again, turn on these options&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and show us the SASLOG.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478509#M286370</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-16T22:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478512#M286371</link>
      <description>&lt;P&gt;The %PUT statement causes the macro calls to %VAREXIST to execute.&amp;nbsp; Try either of these instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put %superq(condition);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put _user_;&amp;nbsp; &amp;nbsp;/* this might give you a bit more than what you want to see */&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478512#M286371</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-16T22:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478515#M286372</link>
      <description>&lt;P&gt;Here is the log file&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478515#M286372</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-16T22:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478517#M286373</link>
      <description>&lt;P&gt;There no %varexist macro anywhere in your log. And what is the %varcond macro shown in the log? Whatever this is, it doesn't relate to your original question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, turn on the options as the first line of your program.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 23:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478517#M286373</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-16T23:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478525#M286374</link>
      <description>&lt;P&gt;If you want to see the macro variables contents without the macro processor evaluating the macro calls then you need to use macro quoting to prevent it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %superq(condition);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or look at it using normal SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  condition=symget('condition');
  put condition=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 02:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478525#M286374</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-17T02:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478537#M286375</link>
      <description>&lt;P&gt;Thank you Tom for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried first option you provided. Now, I see "&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,var1) and %varexist(sdtmcro.&amp;amp;dsn,var2)" in log or in program where I recall it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am having one more trouble.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my other program, I am calling this %varcond in %if condition as follow:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if %varcond(&amp;amp;dsn) %then %do;&lt;/P&gt;&lt;P&gt;proc sort data=sdtmcro.&amp;amp;dsn out=&amp;amp;dsn;&lt;BR /&gt;by usubjid ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, I get following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Required operator not found in expression: %varcond(&amp;amp;dsn)&lt;BR /&gt;MLOGIC(VARCOND): %PUT %superq(varcondn)&lt;BR /&gt;WARNING: Apparent symbolic reference VARCONDN not resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to run do loop by checking this condition:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if %varcond %then %do= %if&amp;nbsp;&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,var1) and %varexist(sdtmcro.&amp;amp;dsn,var2) %then %do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please let me know what would resolve this problem.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 02:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478537#M286375</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-17T02:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478538#M286376</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _temp_;
domain="&amp;amp;dsn";
%do i =1 %to %sysfunc(countw(&amp;amp;variables.));
%let var=%scan(&amp;amp;variables.,&amp;amp;i);
varcond= "%"||"varexist(sdtmcro.&amp;amp;dsn,&amp;amp;var)";
output;
%end;
run;
 
data _TEMP2_;
  length CONDN $500;
  retain CONDN;
  set _TEMP_;
  CONDN=catx(' and ',CONDN, VARCOND);
  call symputx('condition', CONDN);
run;

%put =&amp;gt; %superq(condition);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;=&amp;gt; %varexist(sdtmcro.&amp;amp;dsn,&amp;amp;var) and %varexist(sdtmcro.&amp;amp;dsn,&amp;amp;var)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You don't need by group processing in your example as variable DOMAIN is a constant;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 02:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478538#M286376</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-17T02:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478550#M286377</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;In my other program, I am calling this %varcond in %if condition as follow:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %varcond(&amp;amp;dsn) %then %do;&lt;/P&gt;
&lt;P&gt;proc sort data=sdtmcro.&amp;amp;dsn out=&amp;amp;dsn;&lt;BR /&gt;by usubjid ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, I get following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Required operator not found in expression: %varcond(&amp;amp;dsn)&lt;BR /&gt;MLOGIC(VARCOND): %PUT %superq(varcondn)&lt;BR /&gt;WARNING: Apparent symbolic reference VARCONDN not resolved.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like you have a bug in the macro %VARCOND().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message says that you are referencing a macro variable named VARCONDN that has not been defined.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps it is just a typo?&amp;nbsp; Is there perhaps a macro variable named VARCOND and you accidentally added an extra N in the %superq() macro function call?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 04:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478550#M286377</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-17T04:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478676#M286378</link>
      <description>&lt;P&gt;Thank you Tom. I made respective changes in my program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I recall macro in following way, there is no error.&lt;/P&gt;&lt;P&gt;%varcond(LB);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MLOGIC(VARCOND): %PUT %superq(varcond)&lt;BR /&gt;%varexist(sdtmcro.LB,LBSTRESC) and %varexist(sdtmcro.LB,LBDRVFL)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I write it in %if condition, I still see this error where "&lt;SPAN&gt;%PUT %superq(varcond)" is blank&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if %varcond(LB) %then %do;&lt;/P&gt;&lt;P&gt;proc sort data=sdtmcro.&amp;amp;dsn out=&amp;amp;dsn;&lt;BR /&gt;by usubjid ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG:&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable DSN resolves to LB&lt;BR /&gt;ERROR: Required operator not found in expression: %varcond(&amp;amp;dsn)&lt;BR /&gt;MLOGIC(VARCOND): %PUT %superq(varcond)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 14:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478676#M286378</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-17T14:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478684#M286379</link>
      <description>&lt;P&gt;Possibly&amp;nbsp;because of a missing semi-colon?&lt;/P&gt;
&lt;P&gt;That could cause the %PUT statement to be waiting for the closing semi-colon so that the %SUPERQ() function does not actually run until after the macro has finished executing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 14:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478684#M286379</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-17T14:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478687#M286380</link>
      <description>&lt;P&gt;You are saying semicolon after "&lt;SPAN&gt;%superq(varcond)" this right?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did put it still shows same error.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 15:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478687#M286380</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-17T15:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478693#M286381</link>
      <description>&lt;P&gt;Thank you Chris.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my other program, I am calling this %varcond in %if condition as follow:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if %varcond(&amp;amp;dsn) %then %do;&lt;/P&gt;&lt;P&gt;proc sort data=sdtmcro.&amp;amp;dsn out=&amp;amp;dsn;&lt;BR /&gt;by usubjid ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, I get following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Required operator not found in expression: %varcond(&amp;amp;dsn)&lt;BR /&gt;MLOGIC(VARCOND): %PUT %superq(varcondn)&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to run do loop by checking this condition:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if %varcond %then %do should be equal to&amp;nbsp; %if&amp;nbsp;&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,var1) and %varexist(sdtmcro.&amp;amp;dsn,var2) %then %do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I recall macro in following way, there is no error.&lt;/P&gt;&lt;P&gt;%varcond(LB);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MLOGIC(VARCOND): %PUT %superq(varcond)&lt;BR /&gt;%varexist(sdtmcro.LB,LBSTRESC) and %varexist(sdtmcro.LB,LBDRVFL)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I write it in %if condition, I still see this error where "&lt;SPAN&gt;%PUT %superq(varcond)" is blank&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if %varcond(LB) %then %do;&lt;/P&gt;&lt;P&gt;proc sort data=sdtmcro.&amp;amp;dsn out=&amp;amp;dsn;&lt;BR /&gt;by usubjid ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG:&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable DSN resolves to LB&lt;BR /&gt;ERROR: Required operator not found in expression: %varcond(&amp;amp;dsn)&lt;BR /&gt;MLOGIC(VARCOND): %PUT %superq(varcond);&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 15:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478693#M286381</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-17T15:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478697#M286382</link>
      <description>&lt;P&gt;Is this the %VARCOND() macro you are trying to call in the middle of a %IF statement?&lt;/P&gt;
&lt;PRE&gt;13         %macro varcond;
14         %let dsn=AE;
15         	data _temp_;
16         			%do i =1 %to %sysfunc(countw(&amp;amp;variables.));
17                			 %let var=%scan(&amp;amp;variables.,&amp;amp;i);
18         				varcond= "%"||"varexist(sdtmcro.&amp;amp;dsn,&amp;amp;var)";
19                			 output;
20         			 %end;
21         			 domain="&amp;amp;dsn";
22         	run;
23         
24         proc sort data=_temp_;
25         by domain ;
26         run;
27         
28         data _temp_;
29         length varcondn $500.;
30         do until(last.domain );
31         set _temp_;
32         by domain ;
33         varcondn=catx(' and ',varcondn,varcond);
34         end;
35         run;
36         
37         proc sql;
38         select varcondn into : varcondn
39         from _temp_;
40         quit;
41         
42         %put &amp;amp;varcondn.;
43         
44         %mend varcond;
&lt;/PRE&gt;
&lt;P&gt;It is generating many many SAS statements. You cannot call that macro in the middle of another statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you write&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %varcond(lb) %then .... &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will generate code into the middle of your %IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if data _tmp_; ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like that macro is intended to set a macro variable named VARCONDN.&lt;/P&gt;
&lt;P&gt;So first create the macro variable. Then call the macro. Then test the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varcondn=0 ;
%varcond;
%if (&amp;amp;varcondn) %then ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478697#M286382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-17T16:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478698#M286383</link>
      <description>&lt;P&gt;Yes. This is the macro I am calling in another program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What will be the best approach to create macro variable which holds the "string" e.g. "&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var1&lt;/SPAN&gt;&lt;SPAN&gt;) and %varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var2&lt;/SPAN&gt;&lt;SPAN&gt;)"&amp;nbsp;&lt;/SPAN&gt;and it can be recalled in another program in IF statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE:&lt;/P&gt;&lt;P&gt;VAR1 and VAR2 can be any variables which are defined in some other macro variable &amp;amp;VARIABLES. This is not constant macro variable, it changes with dataset name.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478698#M286383</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-17T16:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478700#M286384</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135083"&gt;@petlove&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What will be the best approach to create macro variable which holds the "string" e.g. "&lt;SPAN&gt;%varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var1&lt;/SPAN&gt;&lt;SPAN&gt;) and %varexist(sdtmcro.&amp;amp;dsn,&lt;/SPAN&gt;&lt;SPAN&gt;var2&lt;/SPAN&gt;&lt;SPAN&gt;)"&amp;nbsp;&lt;/SPAN&gt;and it can be recalled in another program in IF statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE:&lt;/P&gt;
&lt;P&gt;VAR1 and VAR2 can be any variables which are defined in some other macro variable &amp;amp;VARIABLES. This is not constant macro variable, it changes with dataset name.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Here is a macro that you can in a "functional" mode. That is it emits only part of a statement. So you could use it inside an IF, %IF or assignment statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varcond(dsn,varlist);
%local i sep ;
%do i=1 %to %sysfunc(countw(&amp;amp;varlist));
  &amp;amp;sep  %varexist(&amp;amp;dsn,%scan(&amp;amp;varlist,&amp;amp;i))
  %let sep=and;
%end;
%mend varcond;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you might use it this way.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;80   options mprint;
81   %let mydataset=SASHELP.CLASS;
82   %let variables=AGE GENDER ;
83   data _null_;
84     if %varcond(&amp;amp;mydataset,&amp;amp;variables) then put "&amp;amp;mydataset has all of the variables: &amp;amp;variables"
84 ! ;
MPRINT(VAREXIST):   3
MPRINT(VARCOND):   and
MPRINT(VAREXIST):   0
85     else put "&amp;amp;mydataset is missing one or more of the variables: &amp;amp;variables";
86   run;

SASHELP.CLASS is missing one or more of the variables: AGE GENDER
NOTE: DATA statement used (Total process time):
      real time           0.26 seconds
      cpu time            0.01 seconds


87
88   %let variables=AGE SEX ;
89   data _null_;
90     if %varcond(&amp;amp;mydataset,&amp;amp;variables) then put "&amp;amp;mydataset has all of the variables: &amp;amp;variables"
90 ! ;
MPRINT(VAREXIST):   3
MPRINT(VARCOND):   and
MPRINT(VAREXIST):   2
91     else put "&amp;amp;mydataset is missing one or more of the variables: &amp;amp;variables";
92   run;

SASHELP.CLASS has all of the variables: AGE SEX
NOTE: DATA statement used (Total process time):
      real time           0.34 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478700#M286384</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-17T16:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478712#M286385</link>
      <description>&lt;P&gt;Thank you&amp;nbsp; so much Tom for your suggestion. The approach you mentioned is working in my program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 16:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable/m-p/478712#M286385</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-07-17T16:37:17Z</dc:date>
    </item>
  </channel>
</rss>

