<?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: Configuration of &amp;quot;mostly reusable&amp;quot; code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789718#M252756</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33000"&gt;@EinarRoed&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33000"&gt;@EinarRoed&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rename;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;program = 2A %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2A;
%end;

%if &amp;amp;program = 2B %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2B;
%end;

%if &amp;amp;program = 2C %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2C;
%end;&lt;BR /&gt;&lt;BR /&gt;%mend&amp;nbsp;rename;&lt;BR /&gt;&lt;BR /&gt;%rename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or maybe something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;program = 2A then do; rename COLUMN_NAME_1 = COLUMN_NAME_2A; end;

if &amp;amp;program = 2B then do; rename COLUMN_NAME_1 = COLUMN_NAME_2B; end;

if &amp;amp;program = 2C then do; rename COLUMN_NAME_1 = COLUMN_NAME_2C; end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The first approach is syntactically correct (but could be simplified, see below), whereas the second approach is not (because the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0x16kvqkxxdx5n1t04voifvo8wo.htm" target="_blank" rel="noopener"&gt;RENAME statement&lt;/A&gt; is not executable and the IF condition uses strings without quotes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of a macro you could use %SYSFUNC(IFC(...)) to create the RENAME statement dynamically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(ifc(%sysfunc(findw(2A 2B 2C,&amp;amp;program)), rename COLUMN_NAME_1 = COLUMN_NAME_&amp;amp;program,));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2022 14:05:41 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2022-01-12T14:05:41Z</dc:date>
    <item>
      <title>Configuration of "mostly reusable" code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789695#M252749</link>
      <description>&lt;P&gt;We have 12 large SAS-scripts that have minimal variations. They're basically just copy-pasted (only 4-5 lines are different). So if we optimize part of the code, we must do the same change in all 12 scripts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've stripped all the scripts down to the bare essentials, and placed the majority of the code into a&amp;nbsp;new reusable script. So when the 12 SAS-scripts run, they %include the new reusable script. So far so good.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that 3 of the 12 SAS-scripts require a few unique columns to be renamed. This must be done roughly in the middle of the new reusable script file. My plan is for the reusable script file to %include a separate script that's used exclusively for renaming. But for now, I just want to make it work within the reusable script itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each of the 12 scripts have a macro variable that indicates the script name. It's called &amp;amp;program and has values such as 1A, 1B, 1C, 2A, 2B, etc. The 3 scripts that require columns to be renamed are 2A, 2B, and 2C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need the code to work something like this (edit: unfortunately, some code becomes poorly structured once I save):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rename;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;program = 2A %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2A;
%end;

%if &amp;amp;program = 2B %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2B;
%end;

%if &amp;amp;program = 2C %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2C;
%end;&lt;BR /&gt;&lt;BR /&gt;%mend&amp;nbsp;rename;&lt;BR /&gt;&lt;BR /&gt;%rename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or maybe something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;program = 2A then do; rename COLUMN_NAME_1 = COLUMN_NAME_2A; end;

if &amp;amp;program = 2B then do; rename COLUMN_NAME_1 = COLUMN_NAME_2B; end;

if &amp;amp;program = 2C then do; rename COLUMN_NAME_1 = COLUMN_NAME_2C; end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So when the reusable script runs, and &amp;amp;prog = 2B, then the line &lt;STRONG&gt;rename COLUMN_NAME_1 = COLUMN_NAME_2B;&lt;/STRONG&gt; should be "applied" in the reusable script.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just can't make it work though. I've tried so many approaches, and never seem to get it just right. Sometimes it just doesn't register, other times I get obscure errors. Ultimately it's just about making if/then work with the &amp;amp;program macro variable within a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would be your recommended approach to solving this problem? I basically just want differential treatment of a few rows within an otherwise huge reusable code.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 13:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789695#M252749</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2022-01-12T13:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Configuration of "mostly reusable" code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789699#M252752</link>
      <description>&lt;P&gt;So, you have a macro that tries to do this, but then you say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I just can't make it work though.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;and we just stare at you with blank faces. How can we help you? We don't know what you have tried, and we don't know why it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you start by sharing the relevant parts of your code that doesn't work? Can you show us the LOG of this part of the code when it doesn't work?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 13:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789699#M252752</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-12T13:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Configuration of "mostly reusable" code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789718#M252756</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33000"&gt;@EinarRoed&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33000"&gt;@EinarRoed&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rename;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;program = 2A %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2A;
%end;

%if &amp;amp;program = 2B %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2B;
%end;

%if &amp;amp;program = 2C %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2C;
%end;&lt;BR /&gt;&lt;BR /&gt;%mend&amp;nbsp;rename;&lt;BR /&gt;&lt;BR /&gt;%rename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or maybe something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;program = 2A then do; rename COLUMN_NAME_1 = COLUMN_NAME_2A; end;

if &amp;amp;program = 2B then do; rename COLUMN_NAME_1 = COLUMN_NAME_2B; end;

if &amp;amp;program = 2C then do; rename COLUMN_NAME_1 = COLUMN_NAME_2C; end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The first approach is syntactically correct (but could be simplified, see below), whereas the second approach is not (because the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0x16kvqkxxdx5n1t04voifvo8wo.htm" target="_blank" rel="noopener"&gt;RENAME statement&lt;/A&gt; is not executable and the IF condition uses strings without quotes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of a macro you could use %SYSFUNC(IFC(...)) to create the RENAME statement dynamically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(ifc(%sysfunc(findw(2A 2B 2C,&amp;amp;program)), rename COLUMN_NAME_1 = COLUMN_NAME_&amp;amp;program,));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 14:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Configuration-of-quot-mostly-reusable-quot-code/m-p/789718#M252756</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-01-12T14:05:41Z</dc:date>
    </item>
  </channel>
</rss>

