<?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: How to write value to a particular column based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795250#M255055</link>
    <description>&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Or you could consider a tranpose to a longer format first and then another to a wide format.&amp;nbsp;&lt;BR /&gt;And sometimes a double transpose is needed for extra wide data sets:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd" target="_blank"&gt;https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to either transpose twice and merge or use a data step merge then where you can do it once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc transpose is a more dynamic approach whereas with a data step you need to know your maximum dimensions ahead of time.&amp;nbsp;&lt;SPAN&gt;Alternatively, you may wan to consider backing up a step and redesign your process and merge to accommodate this ahead of time somehow.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="line-height: 1.71429;"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 17:51:51 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-02-09T17:51:51Z</dc:date>
    <item>
      <title>How to write value to a particular column based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795212#M255038</link>
      <description>&lt;P&gt;I have the following dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;This dataset was obtained by joining with the table the val is present it and matching with either val1=val or val2=val. Since both matched, there are 2 rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to transform this into a single row per id as follows so that all the values in the val column are shown in the same row:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val1match&amp;nbsp; &amp;nbsp;val2match&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If for a certain ID, there is only one match and hence there is only one row to begin with like this:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;that should be transformed as follows:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val1match&amp;nbsp; &amp;nbsp;val2match&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 16:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795212#M255038</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-02-09T16:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to write value to a particular column based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795216#M255039</link>
      <description>&lt;P&gt;Transpose the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want prefix=match_val;
by id val1 val2;
var val;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the following dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;This dataset was obtained by joining with the table the val is present it and matching with either val1=val or val2=val. Since both matched, there are 2 rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to transform this into a single row per id as follows so that all the values in the val column are shown in the same row:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val1match&amp;nbsp; &amp;nbsp;val2match&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If for a certain ID, there is only one match and hence there is only one row to begin with like this:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;that should be transformed as follows:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;val1&amp;nbsp; &amp;nbsp;val2&amp;nbsp; &amp;nbsp;val1match&amp;nbsp; &amp;nbsp;val2match&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 16:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795216#M255039</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-09T16:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to write value to a particular column based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795221#M255040</link>
      <description>Thanks for the response! I tried this out but I actually have multiple columns that I want to put in the var statement so it's giving me 1 row for each column that I put there&lt;BR /&gt;So basically, there's val and code. Each val has a corresponding code. I'm not trying to match the code with anything when I join but I just want that displayed there from this:&lt;BR /&gt;ID   val1   val2   val   code&lt;BR /&gt;1    1        2        1      3&lt;BR /&gt;1    1        2        2      4&lt;BR /&gt;to this:&lt;BR /&gt;ID   val1   val2   val1match   code1   val2match   code2&lt;BR /&gt;1     1       2        1                  3            2                4&lt;BR /&gt;&lt;BR /&gt;The order of columns can differ but I just want them there</description>
      <pubDate>Wed, 09 Feb 2022 17:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795221#M255040</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-02-09T17:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to write value to a particular column based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795250#M255055</link>
      <description>&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Or you could consider a tranpose to a longer format first and then another to a wide format.&amp;nbsp;&lt;BR /&gt;And sometimes a double transpose is needed for extra wide data sets:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd" target="_blank"&gt;https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to either transpose twice and merge or use a data step merge then where you can do it once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc transpose is a more dynamic approach whereas with a data step you need to know your maximum dimensions ahead of time.&amp;nbsp;&lt;SPAN&gt;Alternatively, you may wan to consider backing up a step and redesign your process and merge to accommodate this ahead of time somehow.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="line-height: 1.71429;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 17:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795250#M255055</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-09T17:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to write value to a particular column based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795348#M255106</link>
      <description>yup! I figured out a way to do it differently. Thank you so much for your help!</description>
      <pubDate>Wed, 09 Feb 2022 21:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-value-to-a-particular-column-based-on-condition/m-p/795348#M255106</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-02-09T21:34:57Z</dc:date>
    </item>
  </channel>
</rss>

