<?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: SAS SQL Join without overwriting the variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965368#M375836</link>
    <description>&lt;P&gt;It would be very difficult to do that with pure SQL code since you do not have anything in the data itself to indicate which value should go to which new variable.&amp;nbsp; This is because SQL is a set operation language.&amp;nbsp; So it does not know or care about the order of the observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If is simple in SAS do this.&amp;nbsp; Use PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want(drop=_name_) prefix=Value_;
  by key;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do it with SQL you will first need to create a new variable so you have something to reference in the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_sql;
  set have;
  by key;
  rowno+1;
  if first.key then rowno=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now it might be possible to use a JOIN .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select * 
from (select key,value as value_1 from for_sql where rowno=1)
natural join (select key,value as value_2 from for_asql where rowno=2)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Apr 2025 16:38:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-04-29T16:38:42Z</dc:date>
    <item>
      <title>SAS SQL Join without overwriting the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965363#M375834</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;I am wondering how to join with sas sql the tables without overwriting the variables.&lt;/P&gt;
&lt;P&gt;For example,&amp;nbsp; I would like to join this data, but in output I would like to have the Value_1=50, Value_2=50.&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 120pt;" border="0" width="160" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 60pt;" span="2" width="80" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="80" height="20" class="xl63" style="height: 15.0pt; width: 60pt;"&gt;Key&lt;/TD&gt;
&lt;TD width="80" class="xl63" style="border-left: none; width: 60pt;"&gt;Value&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;PI23X&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;PI23X&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you foryour help !&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 15:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965363#M375834</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-04-29T15:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL Join without overwriting the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965366#M375835</link>
      <description>&lt;P&gt;Please give a more complete question. Show us a data set with multiple values of KEY. Show us a data set with multiple values of VALUE. Show us an example of a data set to join with. Show us the desired output as a table, not words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, why SQL here? If we can get the result a different way without SQL, is that acceptable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have been in this forum for a long time, and we have helped you with many problems. You have to help us as well, by posting data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), and not in other formats. Please do that in your answer to my questions above.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 16:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965366#M375835</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-29T16:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL Join without overwriting the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965368#M375836</link>
      <description>&lt;P&gt;It would be very difficult to do that with pure SQL code since you do not have anything in the data itself to indicate which value should go to which new variable.&amp;nbsp; This is because SQL is a set operation language.&amp;nbsp; So it does not know or care about the order of the observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If is simple in SAS do this.&amp;nbsp; Use PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want(drop=_name_) prefix=Value_;
  by key;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do it with SQL you will first need to create a new variable so you have something to reference in the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_sql;
  set have;
  by key;
  rowno+1;
  if first.key then rowno=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now it might be possible to use a JOIN .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select * 
from (select key,value as value_1 from for_sql where rowno=1)
natural join (select key,value as value_2 from for_asql where rowno=2)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 16:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965368#M375836</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-29T16:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL Join without overwriting the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965388#M375840</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;I am wondering how to join with sas sql the tables without overwriting the variables.&lt;/P&gt;
&lt;P&gt;For example,&amp;nbsp; I would like to join this data, but in output I would like to have the Value_1=50, Value_2=50.&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 120pt;" border="0" width="160" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 60pt;" span="2" width="80" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="80" height="20" class="xl63" style="height: 15.0pt; width: 60pt;"&gt;Key&lt;/TD&gt;
&lt;TD width="80" class="xl63" style="border-left: none; width: 60pt;"&gt;Value&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;PI23X&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;PI23X&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you foryour help !&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In addition, it would be a good idea to show the code that is generating this "overwrite" of the variable. I am actually suspecting what&amp;nbsp; you are seeing is duplication of key with different values of "value". &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It really isn't clear if "Value_1=50, Value_2=50" means that you have two variable on an observation with different values or not.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 20:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965388#M375840</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-04-29T20:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL Join without overwriting the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965542#M375881</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Thank you for your message.&lt;BR /&gt;I have different values, for example, Value_1=50, Value_2=70&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2025 17:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965542#M375881</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-05-01T17:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL Join without overwriting the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965545#M375882</link>
      <description>Thank you, Tom!</description>
      <pubDate>Thu, 01 May 2025 18:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Join-without-overwriting-the-variable/m-p/965545#M375882</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-05-01T18:44:34Z</dc:date>
    </item>
  </channel>
</rss>

