<?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: Creating a (macro) variable from a macro variable containing a list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691794#M210623</link>
    <description>Hi Reeza,&lt;BR /&gt;The variable 'SEX' is specified in a previous part of my code as a covariate in a regression model. In the new macro I'm referring to, I wanted to decide which block of code to run. That's to say, if 'SEX' is part of the covariates in the model, then run a block, else run the other one. I tried the FIND function, but I could not get the answer I needed. I wasn't sure who to make work in my example. See reply by RichardAdeVenezia, that worked for me.&lt;BR /&gt;Thank you!</description>
    <pubDate>Thu, 15 Oct 2020 11:38:57 GMT</pubDate>
    <dc:creator>alexgonzalez</dc:creator>
    <dc:date>2020-10-15T11:38:57Z</dc:date>
    <item>
      <title>Creating a (macro) variable from a macro variable containing a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691641#M210536</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to create a macro that needs to identify whether a macro variable previously defined contains certain variable. For example, I first created the macro variable 'covariates' as shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let covariates = seq weekend sex;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, the following macro runs a block of code depending whether the variable 'sex' is included in &amp;amp;covariates&amp;nbsp; or not (See red text below).&lt;/P&gt;
&lt;P&gt;%macro test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*The two lines of code below are to show what I, not how;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"if &amp;amp;covariates contains SEX" then &amp;amp;sex=1;&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else &amp;amp;sex=0;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %if %sysevalf(&amp;amp;sex=1) %then %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%else %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%end;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;Can you please advice?&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 19:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691641#M210536</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2020-10-14T19:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a (macro) variable from a macro variable containing a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691644#M210538</link>
      <description>&lt;P&gt;Where will this occur? Within a data step, SQL or open code? What should happen in the end, a new variable is being created or a new macro variable? What is the macro variable sex coming from and what value does that contain? Why the duplicate logic as well, is there a specific reason to create that variable rather than go straight into the IF/THEN logic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to isolating terms, you can use regular functions like FIND but you need to use SYSFUNC() within the macro language.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 19:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691644#M210538</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-14T19:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a (macro) variable from a macro variable containing a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691648#M210541</link>
      <description>&lt;P&gt;Use the base function INDEXW to detect the position of a word in a delimited list of words.&amp;nbsp; If not found the result will be zero, so you can use the result as a logical test for presence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INDEXW is case sensitive so you need to be careful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example&lt;/P&gt;
&lt;PRE&gt;%let itemlist = seq weekend sex;
%put NOTE: token SEX at position %sysfunc(indexw(%upcase(&amp;amp;itemlist),SEX));&lt;BR /&gt;%put NOTE: token WEEKDAY at position %sysfunc(indexw(%upcase(&amp;amp;itemlist),WEEKDAY));&lt;/PRE&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;PRE&gt;NOTE: token SEX at position 13&lt;BR /&gt;NOTE: token WEEKDAY at position 0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 19:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691648#M210541</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-14T19:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a (macro) variable from a macro variable containing a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691792#M210621</link>
      <description>Thanks Richard, that's exaclty what I needed.</description>
      <pubDate>Thu, 15 Oct 2020 11:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691792#M210621</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2020-10-15T11:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a (macro) variable from a macro variable containing a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691794#M210623</link>
      <description>Hi Reeza,&lt;BR /&gt;The variable 'SEX' is specified in a previous part of my code as a covariate in a regression model. In the new macro I'm referring to, I wanted to decide which block of code to run. That's to say, if 'SEX' is part of the covariates in the model, then run a block, else run the other one. I tried the FIND function, but I could not get the answer I needed. I wasn't sure who to make work in my example. See reply by RichardAdeVenezia, that worked for me.&lt;BR /&gt;Thank you!</description>
      <pubDate>Thu, 15 Oct 2020 11:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-variable-from-a-macro-variable-containing-a/m-p/691794#M210623</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2020-10-15T11:38:57Z</dc:date>
    </item>
  </channel>
</rss>

