<?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 Assign one value to duplicate variables across rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909798#M83208</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am trying to assign a value to duplicate rows.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;This is the data I have:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Medrec Results&amp;nbsp;&lt;BR /&gt;771441 Growth&lt;BR /&gt;771441 Growth&lt;BR /&gt;771441 No Growth&lt;BR /&gt;771441 No Growth&lt;BR /&gt;771441 No Growth&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;This is the data I want:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Medrec Results Growth&lt;BR /&gt;771441 Growth Y&lt;BR /&gt;771441 Growth Y&lt;BR /&gt;771441 No Growth Y&lt;BR /&gt;771441 No Growth Y&lt;BR /&gt;771441 No Growth Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I've tried but I only get one row to have Growth = 'Y'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data = medrec2; by medrec results;run;&lt;/DIV&gt;&lt;DIV&gt;data medrec3;&lt;/DIV&gt;&lt;DIV&gt;set medrec2;&lt;/DIV&gt;&lt;DIV&gt;by medrec;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if first.Medrec then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if results = 'Growth' then growth = 'y';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else if results = 'No Growth' then growth = 'n';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you!!&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2023 04:55:47 GMT</pubDate>
    <dc:creator>hameliz</dc:creator>
    <dc:date>2023-12-28T04:55:47Z</dc:date>
    <item>
      <title>Assign one value to duplicate variables across rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909798#M83208</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am trying to assign a value to duplicate rows.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;This is the data I have:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Medrec Results&amp;nbsp;&lt;BR /&gt;771441 Growth&lt;BR /&gt;771441 Growth&lt;BR /&gt;771441 No Growth&lt;BR /&gt;771441 No Growth&lt;BR /&gt;771441 No Growth&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;This is the data I want:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Medrec Results Growth&lt;BR /&gt;771441 Growth Y&lt;BR /&gt;771441 Growth Y&lt;BR /&gt;771441 No Growth Y&lt;BR /&gt;771441 No Growth Y&lt;BR /&gt;771441 No Growth Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I've tried but I only get one row to have Growth = 'Y'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data = medrec2; by medrec results;run;&lt;/DIV&gt;&lt;DIV&gt;data medrec3;&lt;/DIV&gt;&lt;DIV&gt;set medrec2;&lt;/DIV&gt;&lt;DIV&gt;by medrec;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if first.Medrec then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if results = 'Growth' then growth = 'y';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else if results = 'No Growth' then growth = 'n';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you!!&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 04:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909798#M83208</guid>
      <dc:creator>hameliz</dc:creator>
      <dc:date>2023-12-28T04:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assign one value to duplicate variables across rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909799#M83209</link>
      <description>&lt;P&gt;You forgot the RETAIN statement so that the value of GROWTH does not get set to missing at the start of each iteration of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also what value to you want it to have if RESULTS is neither Growth nor No Growth?&amp;nbsp; If you don't have another ELSE clause then any MEDREC group where the first value is neither of those two very specific values will retain the value calculated for the previous group.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 05:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909799#M83209</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-28T05:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assign one value to duplicate variables across rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909800#M83210</link>
      <description>Thank you!&amp;nbsp; Where would I put 'Retain'?&lt;BR /&gt;&lt;BR /&gt;And there are only two options = 'Growth' or 'No Growth'.&lt;BR /&gt;&lt;BR /&gt;thanks!</description>
      <pubDate>Thu, 28 Dec 2023 05:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909800#M83210</guid>
      <dc:creator>hameliz</dc:creator>
      <dc:date>2023-12-28T05:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assign one value to duplicate variables across rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909801#M83211</link>
      <description>&lt;P&gt;I just did some searching and added it like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;proc sort data = medrec2; by medrec results;run;&lt;/DIV&gt;&lt;DIV&gt;data medrec3;&lt;/DIV&gt;&lt;DIV&gt;set medrec2;&lt;/DIV&gt;&lt;DIV&gt;by medrec;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if first.Medrec then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;retain growth;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if results = 'Growth' then growth = 'y';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else if results = 'No Growth' then growth = 'n';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;and it worked!!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 Dec 2023 05:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909801#M83211</guid>
      <dc:creator>hameliz</dc:creator>
      <dc:date>2023-12-28T05:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Assign one value to duplicate variables across rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909802#M83212</link>
      <description>&lt;P&gt;&amp;nbsp;It just tells SAS not to reset the new variable to missing at the start of the next iteration.&amp;nbsp; So since it has no executable component you can place the retain statement any where in the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0t2ac0tfzcgbjn112mu96hkgg9o.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0t2ac0tfzcgbjn112mu96hkgg9o.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 05:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909802#M83212</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-28T05:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign one value to duplicate variables across rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909803#M83213</link>
      <description>&lt;P&gt;If you only have two possible values then why not just create a binary variable.&amp;nbsp; That is easier to create&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data medrec3;
  set medrec2;
  by medrec;
  if first.Medrec then growth= (results = 'Growth');
  retain growth;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and easier to work with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 05:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-one-value-to-duplicate-variables-across-rows/m-p/909803#M83213</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-28T05:17:43Z</dc:date>
    </item>
  </channel>
</rss>

