<?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: Give the same value in column, based on another column value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706272#M26349</link>
    <description>Thank you so much, it worked clearly! Have a nice day and thank you, next time I will write the type of variables i have.</description>
    <pubDate>Wed, 16 Dec 2020 09:54:54 GMT</pubDate>
    <dc:creator>fcf</dc:creator>
    <dc:date>2020-12-16T09:54:54Z</dc:date>
    <item>
      <title>Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706251#M26338</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Hello!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I have these three columns: name, cod and id. Based on the same value in "name" on the previous row I want to provide the same cod on the id column, which is also the previous id/cod. When there is no cod associated with the name in any row, I want to keep it as blank.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;So this is what I have:&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Name&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;cod&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;id&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Ana Maria Santos&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Ana Maria Santos&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Ana Maria Santos&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;João Pedro Costa&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;João Pedro Costa&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Diogo Silva&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Diogo Silva&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Diogo Silva&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;And this is what I want:&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Name&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;cod&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;id&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Ana Maria Santos&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Ana Maria Santos&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Ana Maria Santos&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;123456789&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;João Pedro Costa&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;João Pedro Costa&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Diogo Silva&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Diogo Silva&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Diogo Silva&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;987654321&lt;/FONT&gt;&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 in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- I've tried merging, but it returns more rows (i don't know why);&lt;/P&gt;&lt;P&gt;- I've tried using first. and last.;&lt;/P&gt;&lt;P&gt;- I've tried using retain but it keeps on also filling the blank ones that I want to keep as blank.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706251#M26338</guid>
      <dc:creator>fcf</dc:creator>
      <dc:date>2020-12-16T09:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706257#M26339</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $ 1-16 cod id;
infile datalines missover;
datalines;
Ana Maria Santos 123456789 123456789
Ana Maria Santos 123456789 123456789
Ana Maria Santos                    
João Pedro Costa                    
João Pedro Costa                    
Diogo Silva      987654321 987654321
Diogo Silva      987654321 987654321
Diogo Silva                         
;

data want(drop=_id);
   set have;
   by Name notsorted;
   if first.Name then call missing(_id);
   if cod then _id = id;
   else         id = _id;
   retain _id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Name             cod       id 
Ana Maria Santos 123456789 123456789 
Ana Maria Santos 123456789 123456789 
Ana Maria Santos .         123456789 
João Pedro Costa .         . 
João Pedro Costa .         . 
Diogo Silva      987654321 987654321 
Diogo Silva      987654321 987654321 
Diogo Silva      .         987654321 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706257#M26339</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-16T09:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706260#M26340</link>
      <description>Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It worked. I just don't understand why I now have '.' in the output in the ones that were blank</description>
      <pubDate>Wed, 16 Dec 2020 09:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706260#M26340</guid>
      <dc:creator>fcf</dc:creator>
      <dc:date>2020-12-16T09:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706262#M26341</link>
      <description>&lt;P&gt;That's why we request that example data is posted in a data step with datalines. Only then will the attributes of columns be clear and unambiguous.&lt;/P&gt;
&lt;P&gt;I guess(!) that in your data cod and id are character, but that was not really clear from the quasi-screenshot you posted.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706262#M26341</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-16T09:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706263#M26342</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355489"&gt;@fcf&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It worked. I just don't understand why I now have '.' in the output in the ones that were blank&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The example that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; used numeric values because you did not indicate one way or the other. The default missing character . is displayed when the value is numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706263#M26342</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T09:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706268#M26345</link>
      <description>&lt;P&gt;ok thank you, next time I will say the type of variables! my variable still remains as character but now it has that point.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706268#M26345</guid>
      <dc:creator>fcf</dc:creator>
      <dc:date>2020-12-16T09:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706270#M26347</link>
      <description>&lt;P&gt;That is because _id will be numeric, as the data step compiler will assume that when the variable is first encountered in the CALL MISSING.&lt;/P&gt;
&lt;P&gt;One needs to take care of all of that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $17. (cod id) (:$10.);
infile datalines truncover;
datalines;
Ana Maria Santos 123456789 123456789
Ana Maria Santos 123456789 123456789
Ana Maria Santos                    
João Pedro Costa                    
João Pedro Costa                    
Diogo Silva      987654321 987654321
Diogo Silva      987654321 987654321
Diogo Silva                         
;

data want(drop=_id);
   set have;
   by Name notsorted;
   length _id $10;
   if first.Name then call missing(_id);
   if cod then _id = id;
   else         id = _id;
   retain _id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also had to change the informat for Name because of the UTF character in &lt;CODE class=" language-sas"&gt;João&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706270#M26347</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-16T09:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706272#M26349</link>
      <description>Thank you so much, it worked clearly! Have a nice day and thank you, next time I will write the type of variables i have.</description>
      <pubDate>Wed, 16 Dec 2020 09:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706272#M26349</guid>
      <dc:creator>fcf</dc:creator>
      <dc:date>2020-12-16T09:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Give the same value in column, based on another column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706273#M26350</link>
      <description>&lt;P&gt;Do not try to "describe" your data. POST A DATA STEP, and all will be well. Code never lies.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Give-the-same-value-in-column-based-on-another-column-value/m-p/706273#M26350</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-16T09:57:31Z</dc:date>
    </item>
  </channel>
</rss>

