<?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: Conditionally create macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606930#M176337</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If the macro variable DSN resolves to 'FACTOR' then I want the macro variable NAME to resolve it as 'AMM' otherwise I want to resolve it how it resolves earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variable NAME is being resolved based on some logic and I want to overwrite that logic only if the value of other macro variable DSN resolves to 'FACTOR'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appericiate if someone of you shed some light on this.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;dsn=FACTOR %then %let name=ANN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that macro variable values do not have quotes around them, and are case sensitive.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Nov 2019 11:45:03 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-11-25T11:45:03Z</dc:date>
    <item>
      <title>Conditionally create macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606918#M176330</link>
      <description>&lt;P&gt;If the macro variable DSN resolves to 'FACTOR' then I want the macro variable NAME to resolve it as 'AMM' otherwise I want to resolve it how it resolves earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variable NAME is being resolved based on some logic and I want to overwrite that logic only if the value of other macro variable DSN resolves to 'FACTOR'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appericiate if someone of you shed some light on this.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 10:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606918#M176330</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-11-25T10:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally create macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606921#M176331</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried this. Let me know!&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic;&lt;BR /&gt;
/* Initialization */
%let NAME = initial_value;
%let DSN = FACTOR;

%put &amp;amp;NAME &amp;amp;DSN;

/* Conditional execution*/
%macro mv();
%if "&amp;amp;DSN" = "FACTOR" %then %do;
	data _null_;
		call symputx("NAME","AMM");
	run;
%end;
%mend;

%mv;

/* Result */

%put &amp;amp;NAME &amp;amp;DSN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 10:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606921#M176331</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-25T10:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally create macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606922#M176332</link>
      <description>&lt;P&gt;Not sure if you're using macro code or data step code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're using macro code then you could try something like the following then check the log for the results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* macro method */
%macro set_name;
   %if &amp;amp;dsn eq FACTOR %then
      %let name = AMM;
%mend set_name;

%let dsn  = ABC;
%let name = XYZ;
%set_name;
%put name = &amp;amp;name;

%let dsn  = FACTOR;
%set_name;
%put name = &amp;amp;name;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you're using data step code then the following should also work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* data step method */
data _null_;
   if "&amp;amp;dsn" eq 'FACTOR' then
      call symputx('name','AMM');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 10:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606922#M176332</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-11-25T10:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally create macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606930#M176337</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If the macro variable DSN resolves to 'FACTOR' then I want the macro variable NAME to resolve it as 'AMM' otherwise I want to resolve it how it resolves earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variable NAME is being resolved based on some logic and I want to overwrite that logic only if the value of other macro variable DSN resolves to 'FACTOR'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appericiate if someone of you shed some light on this.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;dsn=FACTOR %then %let name=ANN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that macro variable values do not have quotes around them, and are case sensitive.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 11:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-create-macro-variable/m-p/606930#M176337</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-25T11:45:03Z</dc:date>
    </item>
  </channel>
</rss>

