<?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 with %do loop and %if-%then/%else Statements won't populate values in data. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748659#M235139</link>
    <description>&lt;P&gt;I'm trying to do something similar to the following. I have data that is similar to the following (apologies, I'm not sure how best to format this in this forum:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SVI                                     Prop_Vax
Low Vulnerability                 .2300
High Vulnerability                .5000
Moderate Vulnerability        .4230&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to create a macro, and as part of that macro, I want to have a data step that creates two new variables a "link" variable for a drill down graph, and a categorical SVI variable utilizing numbers rather than the full text value. Right now, I have the code as such:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET SVI1=Low Vulnerability;
%LET SVI2=Moderate Vulnerability;
%LET SVI3=High Vulnerability;

%macro COVID_Data;
data covid2;
set covid;
SVIcat2=.;
Link=" ";
%do i=1 %to 3;
%if SVI="&amp;amp;&amp;amp;SVI&amp;amp;i" %then SVIcat2=i;
%else %if SVI=" " %then SVIcat2=.;
%end;
%do i=1 %to 3;
%if SVI="&amp;amp;&amp;amp;SVI&amp;amp;i" %then link="vuln&amp;amp;i..html";
%else %if SVI=" " %then link=" ";
%end;
run;
%mend COVID_Data;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I run the macro, it doesn't actually produce values in the columns for the "SVIcat2" and "Link" variables, and I can't figure out why. Can someone explain what I am doing incorrectly?&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jun 2021 12:23:18 GMT</pubDate>
    <dc:creator>jlc35</dc:creator>
    <dc:date>2021-06-17T12:23:18Z</dc:date>
    <item>
      <title>Macro with %do loop and %if-%then/%else Statements won't populate values in data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748659#M235139</link>
      <description>&lt;P&gt;I'm trying to do something similar to the following. I have data that is similar to the following (apologies, I'm not sure how best to format this in this forum:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SVI                                     Prop_Vax
Low Vulnerability                 .2300
High Vulnerability                .5000
Moderate Vulnerability        .4230&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to create a macro, and as part of that macro, I want to have a data step that creates two new variables a "link" variable for a drill down graph, and a categorical SVI variable utilizing numbers rather than the full text value. Right now, I have the code as such:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET SVI1=Low Vulnerability;
%LET SVI2=Moderate Vulnerability;
%LET SVI3=High Vulnerability;

%macro COVID_Data;
data covid2;
set covid;
SVIcat2=.;
Link=" ";
%do i=1 %to 3;
%if SVI="&amp;amp;&amp;amp;SVI&amp;amp;i" %then SVIcat2=i;
%else %if SVI=" " %then SVIcat2=.;
%end;
%do i=1 %to 3;
%if SVI="&amp;amp;&amp;amp;SVI&amp;amp;i" %then link="vuln&amp;amp;i..html";
%else %if SVI=" " %then link=" ";
%end;
run;
%mend COVID_Data;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I run the macro, it doesn't actually produce values in the columns for the "SVIcat2" and "Link" variables, and I can't figure out why. Can someone explain what I am doing incorrectly?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 12:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748659#M235139</guid>
      <dc:creator>jlc35</dc:creator>
      <dc:date>2021-06-17T12:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with %do loop and %if-%then/%else Statements won't populate values in data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748664#M235143</link>
      <description>&lt;P&gt;Use the DATA step and arrays, not macros for this. Understand that the macro processing executes first, before the data are read.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 12:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748664#M235143</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-06-17T12:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with %do loop and %if-%then/%else Statements won't populate values in data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748672#M235145</link>
      <description>&lt;P&gt;A condition like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if SVI="&amp;amp;&amp;amp;SVI&amp;amp;i"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can NEVER be true, as the&amp;nbsp;&lt;EM&gt;text&lt;/EM&gt; SVI can never be equal to a&amp;nbsp;&lt;EM&gt;text&lt;/EM&gt; containing quotes, no matter what the macro variables resolve to.&lt;/P&gt;
&lt;P&gt;The mistake comes from the misunderstanding of what a macro does, and when it does it. The macro can never have access to data that will be present once the code executes &lt;EM&gt;after the macro created it&lt;/EM&gt;. You cannot use values in variables that will be present only once the data step &lt;EM&gt;created by the macro&lt;/EM&gt; is compiled and executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro is for handling code, not for handling data. Print that on a large sheet in very large letters and fix it above your desk.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 12:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-do-loop-and-if-then-else-Statements-won-t-populate/m-p/748672#M235145</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-17T12:52:10Z</dc:date>
    </item>
  </channel>
</rss>

