<?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: Combining two rows into one + create new versions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414766#M101651</link>
    <description>Yes, variable names are important. V1 etc. is just an example (variable 1), but the names are more specific - they're address types, for example V1 is an address where a certain person lives and V2 is an address of his company. The problem I have is that some records have identical modification date but different values and I'd like to output it as a new version of the same address type. As for the order of values - since the modification dates are the same, I cannot say which version is newer, I just need to provide different variations. So to answer your question - the order of values is not important.</description>
    <pubDate>Mon, 20 Nov 2017 07:23:42 GMT</pubDate>
    <dc:creator>Dontik</dc:creator>
    <dc:date>2017-11-20T07:23:42Z</dc:date>
    <item>
      <title>Combining two rows into one + create new versions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414723#M101630</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having a trouble with combining two or more rows with the same id into one. I have something like this:&lt;/P&gt;
&lt;P&gt;ID | V1 | V2 |... |V10|&lt;BR /&gt;1 &amp;nbsp;| str | &amp;nbsp; &amp;nbsp; &amp;nbsp; |... | &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&lt;BR /&gt;1 &amp;nbsp;| &amp;nbsp; &amp;nbsp; &amp;nbsp; |str2|... | &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I'd like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID | V1 | V2|...|V10&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp;| str |str2|...|&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To sum up, I want to combine those two rows into single one like this one. But that's just the beginning. Imagine I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID | V1 | V2 |... |V10|&lt;BR /&gt;1 &amp;nbsp;| str | &amp;nbsp; &amp;nbsp; &amp;nbsp; |... |str3 |&lt;BR /&gt;1 &amp;nbsp;| &amp;nbsp; &amp;nbsp; &amp;nbsp; |str2|... |str4 |&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would need is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID | V1 | V2 |... |V10|V10v2|&lt;BR /&gt;1 &amp;nbsp;| str |str2|... |str3|str4 &amp;nbsp; &amp;nbsp; |&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if there are more filled rows for a certain column, there should be version 3, 4, 5 and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd be grateful for you help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you im advance!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 22:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414723#M101630</guid>
      <dc:creator>Dontik</dc:creator>
      <dc:date>2017-11-19T22:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two rows into one + create new versions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414730#M101632</link>
      <description>&lt;P&gt;Make it long first, so that you have a unique key for each row, which is a combination of ID and V1, V10V2 or however you want to count that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i.e.:&lt;/P&gt;
&lt;P&gt;ID Version Value&lt;/P&gt;
&lt;P&gt;1 1 str1&lt;/P&gt;
&lt;P&gt;1 2 str2&lt;/P&gt;
&lt;P&gt;1 10 str3&lt;/P&gt;
&lt;P&gt;1 10 str4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then add a second identifier:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Version Counter Value&lt;/P&gt;
&lt;P&gt;1 1 1 str1&lt;/P&gt;
&lt;P&gt;1 2 1 str2&lt;/P&gt;
&lt;P&gt;1 10 1 str3&lt;/P&gt;
&lt;P&gt;1 10 2 str4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can transpose it to a wide format again.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the most dynamic approach that I can think of and can be handled with a PROC TRANSPOSE, a DATA STEP to add the COUNTER variable and a second PROC TRANSPOSE to a wide format again. You may want to consider storing the data in a long format overall.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 00:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414730#M101632</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-20T00:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two rows into one + create new versions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414758#M101647</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28124"&gt;@Dontik&lt;/a&gt;, in your example, when same variable have more than one observation per ID,&lt;/P&gt;
&lt;P&gt;as for: ID=1&amp;nbsp; V10 in (str3 str4) you want output in two variables: v10, v10v2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the varaible name important or can it be v10, v11, etc. ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about input like:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ID | V1 | V2 |... |V10|&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 &amp;nbsp;| str | &amp;nbsp; &amp;nbsp; &amp;nbsp; |... |str3 |&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 &amp;nbsp;| &amp;nbsp; &amp;nbsp; &amp;nbsp; |str2|... |str4 |&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|str5|... |str6 |&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;should the varaibles be:&amp;nbsp; v1, v2, &lt;STRONG&gt;v2v2&lt;/STRONG&gt;, ...,v10, &lt;STRONG&gt;v10v2&lt;/STRONG&gt;, &lt;STRONG&gt;v10v3 etc.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;OR&amp;nbsp;&lt;/STRONG&gt;may I call them: v1, v2, v3, ... v10, v11, v12, ... Vn&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- as much variables as need to include all values per ID ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;-&amp;nbsp;is the order of values important? should it be:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; str, str2, str5, strt3, str4, str6&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; OR&amp;nbsp; &amp;nbsp;str, str3, str2, str4, str5, str6&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you give some more information what kind of data is it?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It may be a clue to give you a better solution.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 06:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414758#M101647</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-20T06:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two rows into one + create new versions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414766#M101651</link>
      <description>Yes, variable names are important. V1 etc. is just an example (variable 1), but the names are more specific - they're address types, for example V1 is an address where a certain person lives and V2 is an address of his company. The problem I have is that some records have identical modification date but different values and I'd like to output it as a new version of the same address type. As for the order of values - since the modification dates are the same, I cannot say which version is newer, I just need to provide different variations. So to answer your question - the order of values is not important.</description>
      <pubDate>Mon, 20 Nov 2017 07:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414766#M101651</guid>
      <dc:creator>Dontik</dc:creator>
      <dc:date>2017-11-20T07:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two rows into one + create new versions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414778#M101658</link>
      <description>&lt;P&gt;Would you like next solution ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input id version address $;
  addr = cat('(',strip(version),') ',strip(address));
  keep id addr;
datalines;
1 1 str1
1 2 str2
1 5 str3
1 5 str4
; run;

proc sort data=test;
  by id addr;
run;

proc transpose data=test 
     out=test1(drop=_name_);
 by id;
 var addr;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;within this method you know what address kind is out of its value instead out of its label.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 08:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414778#M101658</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-20T08:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two rows into one + create new versions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414817#M101669</link>
      <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;update have(obs=0) have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 12:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-rows-into-one-create-new-versions/m-p/414817#M101669</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-20T12:53:53Z</dc:date>
    </item>
  </channel>
</rss>

