<?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: Replace and insert values in dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/325024#M72237</link>
    <description>&lt;P&gt;A variation for multiple "-----" values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have1;&lt;/P&gt;
&lt;P&gt;if name = '-----' then do i=1 to _nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have2 point=i nobs=_nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;name=filler;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else output;&lt;/P&gt;
&lt;P&gt;drop filler;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jan 2017 13:18:11 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-01-16T13:18:11Z</dc:date>
    <item>
      <title>Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324972#M72218</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get the below output. I have tried a few things but was not able to get what i wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets, have1 and have2, i want to search for a string in have1 and insert values from dataset 2 when there is a specific value.&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
length name $5;
input name ;
datalines;
ABC
EFD
-----
FGH
;
run;

data have2;
length filler $5;
input filler;
datalines;
FFF
GGG
HHH
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the final dataset want will be used to write out to a text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Manjeet&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 08:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324972#M72218</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-01-16T08:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324978#M72219</link>
      <description>&lt;P&gt;Please use a data step and post complete example data, so it is easier to recreate the datasets and understand the issue.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 07:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324978#M72219</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-16T07:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324982#M72220</link>
      <description>&lt;P&gt;done.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 08:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324982#M72220</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-01-16T08:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324984#M72222</link>
      <description>&lt;P&gt;OK, so the ----- is one observation and not a certain sequence of observations.&lt;/P&gt;
&lt;P&gt;Based on what I remember from your original intended result, this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have1;
if name = '-----'
then do until (done);
  set have2 end=done;
  name=filler;
  output;
end;
else output;
drop filler;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will fail if you have more than one "-----" observation.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 08:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324984#M72222</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-16T08:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324998#M72226</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you won't mind transforming have2 by including a key and index, you could try this which will work for every&amp;nbsp;'-----' found in have1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* create key and index over have2;
data have3 (index=(NAME));
set have2;
NAME='-----';
run;

data want;
set have1;
drop FILLER;

do until (_ERROR_); * cycle through have2;
   set have3 key=NAME; 
   if not _ERROR_ then do; * match;	  
      NAME=FILLER;
      output;
	  NAME='-----';	  
   end;
   else if NAME ne '-----' then output; * no match;
end;
_ERROR_=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What you are trying to do is actually a left join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code above is an old technique which uses an index&amp;nbsp;to reset the cursor over have2 when the key will not match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other similar approaches could be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Load have2 into an hash table and iterate through it.&lt;/P&gt;
&lt;P&gt;SQL left join of have1 with have2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 10:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/324998#M72226</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-16T10:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/325024#M72237</link>
      <description>&lt;P&gt;A variation for multiple "-----" values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have1;&lt;/P&gt;
&lt;P&gt;if name = '-----' then do i=1 to _nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have2 point=i nobs=_nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;name=filler;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else output;&lt;/P&gt;
&lt;P&gt;drop filler;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 13:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/325024#M72237</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-16T13:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Replace and insert values in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/325914#M72540</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks Kurt. this is exactly what i was looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers from India!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Manjeet&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 09:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-and-insert-values-in-dataset/m-p/325914#M72540</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-01-19T09:18:46Z</dc:date>
    </item>
  </channel>
</rss>

