<?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: Macro using IF, THEN and ELSE, variable with in operator and do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427885#M105575</link>
    <description>&lt;P&gt;Reeza, I have many hospitals' data and it is in different formats and some fields are named differently.&amp;nbsp;&amp;nbsp;I actually have many of the same report per site which is labour intensive when I have to update so I would like one report where I enter the site in a variable and the report produces only for that site, I change the variable and run again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this instance, the field of CCI status is different for some sites versus others so I wanted to use the same rename macro as always BUT have an if statement as to what field to rename depending on the site.&amp;nbsp; If it is sites a, b and c then the source field for the status&amp;amp;i = pxattr&amp;amp;i else the source is pxstat&amp;amp;i.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jan 2018 23:45:25 GMT</pubDate>
    <dc:creator>shellp55</dc:creator>
    <dc:date>2018-01-15T23:45:25Z</dc:date>
    <item>
      <title>Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427877#M105570</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a report where the sources for the same report may differ so I need to rename some fields.&amp;nbsp; So if the variable field of inst_no includes those in the incl_list then rename using one field otherwise use another field.&amp;nbsp; Below is wrong but I've been working on this forever so hopefully someone can help.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let inst_no=5555;
%let incl_list=3333, 4444, 5555, 6666;

%macro renm1;
%if &amp;amp;inst_no. in (&amp;amp;incl_list) %then %do I = 0 %to 20;
status&amp;amp;i=pxattr&amp;amp;i;
else %do i = 0 %to 20;
status&amp;amp;i=pxstat&amp;amp;i;
%end;
%mend;&lt;BR /&gt;&lt;BR /&gt;Data have;&lt;BR /&gt;set mydata;&lt;BR /&gt;rename %renm1;&lt;BR /&gt;run;&lt;BR /&gt;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427877#M105570</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-15T23:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427878#M105571</link>
      <description>&lt;P&gt;You need the mindelimiter option in your macro statement. I hope I have corrected your code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let inst_no=5555;
%let incl_list=3333, 4444, 5555, 6666;

%macro renm1/mindelimiter=',';
%if &amp;amp;inst_no. in (&amp;amp;incl_list) %then %do I = 0 %to 20;
status&amp;amp;i=pxattr&amp;amp;i;
%else %do i = 0 %to 20;
status&amp;amp;i=pxstat&amp;amp;i;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427878#M105571</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-15T23:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427879#M105572</link>
      <description>&lt;P&gt;Its not 100% clear on what you're doing but I would probably drive the rules using a mapping table of some sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you illustrate your issue with some sample data?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427879#M105572</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-15T23:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427882#M105574</link>
      <description>&lt;P&gt;Thanks for the speedy reply but the same error message is showing up "required operator not found in expression:&amp;nbsp; &amp;nbsp;&amp;amp;inst_no. in (&amp;amp;incl_list).&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427882#M105574</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-15T23:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427885#M105575</link>
      <description>&lt;P&gt;Reeza, I have many hospitals' data and it is in different formats and some fields are named differently.&amp;nbsp;&amp;nbsp;I actually have many of the same report per site which is labour intensive when I have to update so I would like one report where I enter the site in a variable and the report produces only for that site, I change the variable and run again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this instance, the field of CCI status is different for some sites versus others so I wanted to use the same rename macro as always BUT have an if statement as to what field to rename depending on the site.&amp;nbsp; If it is sites a, b and c then the source field for the status&amp;amp;i = pxattr&amp;amp;i else the source is pxstat&amp;amp;i.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427885#M105575</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-15T23:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427887#M105576</link>
      <description>&lt;P&gt;I would say make a table with the variables for each report.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use a portion of your code to select the relevant names from that table. Otherwise you're hard coding the logic which is harder to maintain long term in my experience, especially if you're working with multiple people.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427887#M105576</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-15T23:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427889#M105577</link>
      <description>&lt;P&gt;I am not sure what you are suggesting Reeza.&amp;nbsp; The data comes from the main DAD data file per site.&amp;nbsp; At the very least can you advise how to successfully use the in statement and save the variables i.e. with or without quotation marks?&amp;nbsp; With or without commas?&amp;nbsp; etc.&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427889#M105577</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-15T23:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427890#M105578</link>
      <description>&lt;P&gt;You don't need to do that. You can rename lists in a single statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rename status1-status20 = pxattr1-pxattr20;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So all you need to do, is define the prefix, if the 20 is fixed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 23:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427890#M105578</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-15T23:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427891#M105579</link>
      <description>&lt;P&gt;Interesting, thanks.&amp;nbsp; I was building off of a previous response on this forum to rename fields for a single site which involved a macro.&amp;nbsp; Glad to know it can be so much simpler, thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427891#M105579</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-16T00:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427892#M105580</link>
      <description>&lt;P&gt;Something like the following would work - I'm not a fan of macro logic, in case you were wondering.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

if &amp;amp;inst_no in (&amp;amp;incl_list) then prefix='pxattr';
else prefix='pxstat';

call symputx('prefix', prefix, 'g');

run;

data have;
set mydata;
rename status1-status20 = &amp;amp;prefix.1-&amp;amp;prefix.20;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427892#M105580</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-16T00:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427895#M105582</link>
      <description>&lt;P&gt;I'm trying to use the if statement with this and I am getting an error of "statement is not valid or it is used out of proper order.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427895#M105582</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-16T00:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427896#M105583</link>
      <description>&lt;P&gt;Post your code and log please.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427896#M105583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-16T00:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427897#M105584</link>
      <description>&lt;P&gt;Great, thanks Reeza!!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427897#M105584</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-16T00:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427899#M105586</link>
      <description>&lt;P&gt;While you already have your answer, sometimes macros are the only or best way to accomplish some things. Not saying this is one of those times, but learning how to tame macros is IMHO an extremely important skill. That said, here is one way you could have gotten your macro to work:&lt;/P&gt;
&lt;PRE&gt;data mydata;
  input status0-status20;
  cards;
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
;

%let inst_no=2222;
%let incl_list=3333,4444,5555,6666;

%macro renm1/mindelimiter=',';
  %if &amp;amp;inst_no. in &amp;amp;incl_list %then %do i = 0 %to 20;
    status&amp;amp;i=pxattr&amp;amp;i
  %end;

  %else %do i = 0 %to 20;
    status&amp;amp;i=pxstat&amp;amp;i
  %end;
%mend;

options minoperator;
data have;
  set mydata;
  rename %renm1;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427899#M105586</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-01-16T00:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro using IF, THEN and ELSE, variable with in operator and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427900#M105587</link>
      <description>&lt;P&gt;Thank you so much!&amp;nbsp; "Taming" is a great&amp;nbsp;description and I will certainly tuck this code away for another day.&amp;nbsp; &amp;nbsp;Thanks for taking the time to respond.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-using-IF-THEN-and-ELSE-variable-with-in-operator-and-do/m-p/427900#M105587</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2018-01-16T00:53:11Z</dc:date>
    </item>
  </channel>
</rss>

