<?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: Add dummy columns in transposed dataset - sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808602#M318843</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/422231"&gt;@melligeri&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use something like the following code. I am not sure about the value "'NULL'" for ID 2, does it represent a missing value or does the transposed data set actually contain the quoted literal value? - In my example code I have understood it as "missing".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xpose;
  ID = 1; PA_1 = 'user1'; PA_2 = 'user2'; output;
  ID = 2; PA_1 = 'user3'; PA_2 = 'user4'; output;
  ID = 3; PA_1 = 'user5'; PA_2 = ''; output;
  ID = 4; PA_1 = 'user6'; PA_2 = 'user7'; output;
run;

data master;
  length ID 8 PA_1-PA_6 $20;
  stop;
run;

data target;
  set master xpose;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="target.gif" style="width: 690px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70597i7D15FAAAB6C923E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="target.gif" alt="target.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2022 15:47:48 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2022-04-19T15:47:48Z</dc:date>
    <item>
      <title>Add dummy columns in transposed dataset - sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808503#M318818</link>
      <description>&lt;P&gt;I have transposed data set&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID        PA_1        PA_2
-------------------------------   
1        user1      user2          
2        user3      user4           
3        user5      'NULL'         
4        user6      user7&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Target data set&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID        PA_1        PA_2        PA_2        PA_2        PA_2        PA_2
---------------------------------------------------------------------------      
1        
2        
3        
4  

  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since the first table is transposed the columns created is dynamic, sometimes it have have PA_1,PA_2 sometimes it can have PA_1,PA_2,PA_3,PA_4,PA_5,PA_6&lt;/P&gt;&lt;P&gt;When I try to join the both the tables using the ID, since there is no other columns other than PA_1 and PA_2, the query fails.&lt;/P&gt;&lt;P&gt;Need a solution to this problem. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 09:07:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808503#M318818</guid>
      <dc:creator>melligeri</dc:creator>
      <dc:date>2022-04-19T09:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add dummy columns in transposed dataset - sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808514#M318824</link>
      <description>&lt;P&gt;Please fix the names in the target dataset, a dataset can't have multiple variable with the same name. And while you are at it, fill the result table with the values from "have"-dataset and post the code you are using to transpose.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 10:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808514#M318824</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-19T10:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Add dummy columns in transposed dataset - sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808562#M318831</link>
      <description>&lt;P&gt;Your description is incomplete.&amp;nbsp; Your sketches of the data is also incomplete since the second dataset has invalid names and no example values.&amp;nbsp; Also it does not look like what you would get from transposing the first dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like you hare transposing data with unknown number of repetitions and so an unknown number of variables are created.&amp;nbsp; That is to be expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the second issue is very unclear.&amp;nbsp; Why would it matter to a merge whether the dataset has 2 or 10 extra variables?&amp;nbsp; A typical merge will look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge a b ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As long as A and B have the variable ID the merge will work.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 14:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808562#M318831</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-19T14:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add dummy columns in transposed dataset - sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808602#M318843</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/422231"&gt;@melligeri&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use something like the following code. I am not sure about the value "'NULL'" for ID 2, does it represent a missing value or does the transposed data set actually contain the quoted literal value? - In my example code I have understood it as "missing".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xpose;
  ID = 1; PA_1 = 'user1'; PA_2 = 'user2'; output;
  ID = 2; PA_1 = 'user3'; PA_2 = 'user4'; output;
  ID = 3; PA_1 = 'user5'; PA_2 = ''; output;
  ID = 4; PA_1 = 'user6'; PA_2 = 'user7'; output;
run;

data master;
  length ID 8 PA_1-PA_6 $20;
  stop;
run;

data target;
  set master xpose;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="target.gif" style="width: 690px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70597i7D15FAAAB6C923E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="target.gif" alt="target.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 15:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-dummy-columns-in-transposed-dataset-sas/m-p/808602#M318843</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-04-19T15:47:48Z</dc:date>
    </item>
  </channel>
</rss>

