<?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: PROC SQL rename variable when creating a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557814#M155555</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266226"&gt;@jeremy4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code below but can someone help me to rename the 'stage' and 'balance' variables (highlighted in red) to something like 'stage_March_2018' and 'balance_March_2018' in dataset B and 'stage_March_2019' and 'balance_March_2019' in dataset A because my current code output only shows for March 2019, whereas I would like the table to show the 'stage' and 'balance' for both March 2018 and March 2019 to see how it has changed? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently, the output based on my code only shows the relevant data for account_ID, stage (from the 2019 dataset), balance&amp;nbsp;(from the 2019 dataset) and time_since_update. Is there a way to change the code to rename 'stage' and 'balance' from the 2018 dataset and have these two renamed columns appear in the output table? I would like the output table to look something like the example below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="March 2018 and March 2019.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29407i3DA969E465EA5698/image-size/large?v=v2&amp;amp;px=999" role="button" title="March 2018 and March 2019.PNG" alt="March 2018 and March 2019.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;data MARCH_2018;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2018;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data MARCH_2019;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2019;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;create table accounts_that_changed as&lt;BR /&gt;&amp;nbsp; &amp;nbsp;select a.account_ID, &lt;FONT color="#FF0000"&gt;a.stage&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;a.balance&lt;/FONT&gt;, a.time_since_update, &lt;FONT color="#FF0000"&gt;b.stage&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;b.balance&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;from MARCH_2018 as a&lt;BR /&gt;&amp;nbsp; &amp;nbsp;inner join MARCH_2019 as b&lt;BR /&gt;&amp;nbsp; &amp;nbsp;on a.account_ID=b.account_ID&lt;BR /&gt;order by a.account_ID&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;proc sql;
   create table accounts_that_changed as
   select a.account_ID, &lt;STRONG&gt;&lt;FONT size="4" color="#FF6600"&gt;a.stage as STAGE_MARCH_2019, a.balance as BALANCE_MARCH_2019, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;   a.time_since_update, b.stage, b.balance
   from MARCH_2018 as a
   inner join MARCH_2019 as b
   on a.account_ID=b.account_ID
order by a.account_ID
;
quit;&lt;/PRE&gt;
&lt;P&gt;Rename variables using AS and then the new name after.&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2019 15:10:39 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-05-10T15:10:39Z</dc:date>
    <item>
      <title>PROC SQL rename variable when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557805#M155549</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code below but can someone help me to rename the 'stage' and 'balance' variables (highlighted in red) to something like 'stage_March_2018' and 'balance_March_2018' in dataset B and 'stage_March_2019' and 'balance_March_2019' in dataset A because my current code output only shows for March 2019, whereas I would like the table to show the 'stage' and 'balance' for both March 2018 and March 2019 to see how it has changed? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, the output based on my code only shows the relevant data for account_ID, stage (from the 2019 dataset), balance&amp;nbsp;(from the 2019 dataset) and time_since_update. Is there a way to change the code to rename 'stage' and 'balance' from the 2018 dataset and have these two renamed columns appear in the output table? I would like the output table to look something like the example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="March 2018 and March 2019.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29407i3DA969E465EA5698/image-size/large?v=v2&amp;amp;px=999" role="button" title="March 2018 and March 2019.PNG" alt="March 2018 and March 2019.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;data MARCH_2018;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2018;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data MARCH_2019;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2019;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;create table accounts_that_changed as&lt;BR /&gt;&amp;nbsp; &amp;nbsp;select a.account_ID, &lt;FONT color="#FF0000"&gt;a.stage&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;a.balance&lt;/FONT&gt;, a.time_since_update, &lt;FONT color="#FF0000"&gt;b.stage&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;b.balance&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;from MARCH_2018 as a&lt;BR /&gt;&amp;nbsp; &amp;nbsp;inner join MARCH_2019 as b&lt;BR /&gt;&amp;nbsp; &amp;nbsp;on a.account_ID=b.account_ID&lt;BR /&gt;order by a.account_ID&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 15:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557805#M155549</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-05-10T15:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL rename variable when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557814#M155555</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266226"&gt;@jeremy4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code below but can someone help me to rename the 'stage' and 'balance' variables (highlighted in red) to something like 'stage_March_2018' and 'balance_March_2018' in dataset B and 'stage_March_2019' and 'balance_March_2019' in dataset A because my current code output only shows for March 2019, whereas I would like the table to show the 'stage' and 'balance' for both March 2018 and March 2019 to see how it has changed? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently, the output based on my code only shows the relevant data for account_ID, stage (from the 2019 dataset), balance&amp;nbsp;(from the 2019 dataset) and time_since_update. Is there a way to change the code to rename 'stage' and 'balance' from the 2018 dataset and have these two renamed columns appear in the output table? I would like the output table to look something like the example below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="March 2018 and March 2019.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29407i3DA969E465EA5698/image-size/large?v=v2&amp;amp;px=999" role="button" title="March 2018 and March 2019.PNG" alt="March 2018 and March 2019.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;data MARCH_2018;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2018;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data MARCH_2019;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2019;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;create table accounts_that_changed as&lt;BR /&gt;&amp;nbsp; &amp;nbsp;select a.account_ID, &lt;FONT color="#FF0000"&gt;a.stage&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;a.balance&lt;/FONT&gt;, a.time_since_update, &lt;FONT color="#FF0000"&gt;b.stage&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;b.balance&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;from MARCH_2018 as a&lt;BR /&gt;&amp;nbsp; &amp;nbsp;inner join MARCH_2019 as b&lt;BR /&gt;&amp;nbsp; &amp;nbsp;on a.account_ID=b.account_ID&lt;BR /&gt;order by a.account_ID&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;proc sql;
   create table accounts_that_changed as
   select a.account_ID, &lt;STRONG&gt;&lt;FONT size="4" color="#FF6600"&gt;a.stage as STAGE_MARCH_2019, a.balance as BALANCE_MARCH_2019, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;   a.time_since_update, b.stage, b.balance
   from MARCH_2018 as a
   inner join MARCH_2019 as b
   on a.account_ID=b.account_ID
order by a.account_ID
;
quit;&lt;/PRE&gt;
&lt;P&gt;Rename variables using AS and then the new name after.&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 15:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557814#M155555</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-10T15:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL rename variable when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557816#M155557</link>
      <description>&lt;P&gt;More than half the time having a wide format with variable names containing actual data, i.e. March, is a poor idea.&lt;/P&gt;
&lt;P&gt;The SQL syntax is to use: value as variablename. The value could be a literal value such as 'ABC' or an existing variable or a calculation: a.stage*a.balance as stagebalance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table accounts_that_changed as
   select a.account_ID, a.stage AS NEWSTAGE, a.balance AS NEWBALANCE, a.time_since_update, b.stage, b.balance
   from MARCH_2018 as a
   inner join MARCH_2019 as b
   on a.account_ID=b.account_ID
order by a.account_ID
;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 May 2019 15:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557816#M155557</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-10T15:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL rename variable when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557824#M155562</link>
      <description>&lt;P&gt;Also note, in the full program you presented, you can uncomplicate things earlier:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data MARCH_2018;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2018;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;rename stage = stage_March_2018;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;rename balance = balance_March_2018;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data MARCH_2019;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set cdp.v_2019;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;rename stage = stage_March_2019;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;rename balance = balance_March_2019;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 15:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-rename-variable-when-creating-a-table/m-p/557824#M155562</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-10T15:22:06Z</dc:date>
    </item>
  </channel>
</rss>

