<?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-number iterative fields in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791320#M253445</link>
    <description>&lt;P&gt;I have a combined dataset containing diagnosis codes from 2 different sources. Each source has multiple diagnosis code fields. &lt;BR /&gt;For brevity, I only added a 7 of the 55 desired diagnosis fields. &lt;FONT color="#3366FF"&gt;Please see attached sample data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to keep the original variables &amp;amp; create a ‘Combined_Dxcode’ variable with 7 fields.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366FF"&gt;so need:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;ComorbidityCode1-ComorbidityCode4 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; 'Combined_Dxcode1 - Combined_Dxcode4'&lt;BR /&gt;DgnsCode1 - DgnsCode3 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; 'Combined_Dxcode5 - Combined_Dxcode7'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jan 2022 23:55:52 GMT</pubDate>
    <dc:creator>eap</dc:creator>
    <dc:date>2022-01-20T23:55:52Z</dc:date>
    <item>
      <title>Re-number iterative fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791320#M253445</link>
      <description>&lt;P&gt;I have a combined dataset containing diagnosis codes from 2 different sources. Each source has multiple diagnosis code fields. &lt;BR /&gt;For brevity, I only added a 7 of the 55 desired diagnosis fields. &lt;FONT color="#3366FF"&gt;Please see attached sample data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to keep the original variables &amp;amp; create a ‘Combined_Dxcode’ variable with 7 fields.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366FF"&gt;so need:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;ComorbidityCode1-ComorbidityCode4 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; 'Combined_Dxcode1 - Combined_Dxcode4'&lt;BR /&gt;DgnsCode1 - DgnsCode3 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; 'Combined_Dxcode5 - Combined_Dxcode7'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 23:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791320#M253445</guid>
      <dc:creator>eap</dc:creator>
      <dc:date>2022-01-20T23:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Re-number iterative fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791333#M253450</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/105081"&gt;@eap&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a combined dataset containing diagnosis codes from 2 different sources. Each source has multiple diagnosis code fields. &lt;BR /&gt;For brevity, I only added a 7 of the 55 desired diagnosis fields. &lt;FONT color="#3366FF"&gt;Please see attached sample data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to keep the original variables &amp;amp; &lt;STRONG&gt;create a ‘Combined_Dxcode’ variable with 7 fields&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366FF"&gt;so need:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;ComorbidityCode1-ComorbidityCode4 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; &lt;FONT color="#FF9900"&gt;'Combined_Dxcode1 - Combined_Dxcode4'&lt;/FONT&gt;&lt;BR /&gt;DgnsCode1 - DgnsCode3 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; &lt;FONT color="#FF9900"&gt;'Combined_Dxcode5 - Combined_Dxcode7'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you creating one or two variables?&lt;/P&gt;
&lt;P&gt;Are you renaming the old variables or are those the names of the new variables. SAS names are typically less than 32 characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either way, here's examples of how to combine and rename and hopefully you can figure it out from here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input ComorbidityCode1 $ ComorbidityCode2 $ ComorbidityCode3 $  ComorbidityCode4 $  DgnsCode1 $ DgnsCode2 $ DgnsCode3 $ @@;
    datalines;
M1611 V1016
T84XA S4587
M1712 A1515
M1630
;
run;

data want;
set have;
DX1_DX3 = catx(", ", of DgnsCode1-DgnsCode3);
CMD1_CMD4 = catx(", ", of ComorbidityCode1-ComorbidityCode4);
All = catx(", " , of DgnsCode1-DgnsCode3, of ComorbidityCode1-ComorbidityCode4 );

rename All = newVariableName;

/*rename a series at once*/
rename DgnsCode1-DgnsCode3=DX1-DX3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FYI - your data step code had a mistake in it, extra $.&amp;nbsp;&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/105081"&gt;@eap&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a combined dataset containing diagnosis codes from 2 different sources. Each source has multiple diagnosis code fields. &lt;BR /&gt;For brevity, I only added a 7 of the 55 desired diagnosis fields. &lt;FONT color="#3366FF"&gt;Please see attached sample data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to keep the original variables &amp;amp; create a ‘Combined_Dxcode’ variable with 7 fields.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366FF"&gt;so need:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;ComorbidityCode1-ComorbidityCode4 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; 'Combined_Dxcode1 - Combined_Dxcode4'&lt;BR /&gt;DgnsCode1 - DgnsCode3 &lt;FONT color="#3366FF"&gt;renamed to&lt;/FONT&gt; 'Combined_Dxcode5 - Combined_Dxcode7'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&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>Fri, 21 Jan 2022 01:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791333#M253450</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-21T01:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Re-number iterative fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791604#M253593</link>
      <description>&lt;P&gt;I'm trying to create 7 consecutive new variables&amp;nbsp;Combined_Dxcode&amp;amp;i where each new field will contain a single, identical diagnosis code from:&lt;/P&gt;
&lt;UL class="lia-list-style-type-disc"&gt;
&lt;LI&gt;the 4 variables ComorbidityCode&amp;amp;i (ComorbidityCode1,&amp;nbsp;ComorbidityCode2,&amp;nbsp;ComorbidityCode3,&amp;nbsp;ComorbidityCode4)&lt;/LI&gt;
&lt;LI&gt;the 3 variables DgnsCode&amp;amp;i (DgnsCode1,&amp;nbsp;DgnsCode2,&amp;nbsp;DgnsCode3,&amp;nbsp;DgnsCode4)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Comorbidity1 &lt;FONT color="#0000FF"&gt;becomes&lt;/FONT&gt; Combined_Dxcode1&lt;/LI&gt;
&lt;LI&gt;Comorbidity4 &lt;FONT color="#0000FF"&gt;becomes&lt;/FONT&gt; Combined_Dxcode4 &lt;FONT color="#0000FF"&gt;BUT&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;DgnsCode1 &lt;FONT color="#0000FF"&gt;becomes&lt;/FONT&gt; Combined_Dxcode5 ...&lt;/LI&gt;
&lt;LI&gt;DgnsCode3 &lt;FONT color="#0000FF"&gt;becomes&lt;/FONT&gt; Combined_Dxcode7&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking something like below but this logic doesn't work correctly for&amp;nbsp;DgnsCode1, DgnsCode2, DgnsCode3&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %do i=1 %to 4;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Combined_Dxcode&amp;amp;i = ComorbidityCode&amp;amp;i;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reeza, thanks for letting me know about the extra '$'!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 23:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791604#M253593</guid>
      <dc:creator>eap</dc:creator>
      <dc:date>2022-01-21T23:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Re-number iterative fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791609#M253596</link>
      <description>&lt;P&gt;You don’t need macro code. You can use it but why not just use two rename statements like I included at the bottom of my example?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jan 2022 00:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-number-iterative-fields/m-p/791609#M253596</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-22T00:40:42Z</dc:date>
    </item>
  </channel>
</rss>

