<?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 value based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337067#M76490</link>
    <description>&lt;P&gt;Not sure if the following meets your conditions, but should come close enough that you can adjust it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=i);
  set have;
  by time notsorted week notsorted;
  array used1(999) _temporary_;
  array used2(999) _temporary_;
  retain used1 used2;
  if first.week then do;
    i=0;
    call missing(of used1(*));
    call missing(of used2(*));
  end;
  i+1;
  if value1 not in used1 then used1(i)=value1;
  else do;
    value1=max(of used1(*))+ceil(100*rand("Uniform"));
    used1(i)=value1;
  end;
  if value2 not in used2 then used2(i)=value2;
  else do;
    value2=max(of used2(*))+ceil(100*rand("Uniform"));
    used2(i)=value2;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2017 16:49:41 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-01T16:49:41Z</dc:date>
    <item>
      <title>replace value based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337002#M76463</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input is time week value1 value2&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 1 2&lt;BR /&gt;1 0 4 1 2&lt;BR /&gt;1 0 4 1 2&lt;BR /&gt;1 1000 8 1 2&lt;BR /&gt;1 1000 8 1 2&lt;BR /&gt;1 0 24 1 2&lt;BR /&gt;1 0 24 1 2&lt;BR /&gt;1 2 24 1 2&lt;BR /&gt;1 2 24 1 2&lt;BR /&gt;1 0 48 1 2&lt;BR /&gt;1 0 48 1 2&lt;BR /&gt;1 2 48 1 2&lt;BR /&gt;1 2 48 1 2&lt;BR /&gt;;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input ID time week value1 value2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 1 2&lt;BR /&gt;1 0 4 0 0&lt;BR /&gt;1 0 4 1 2&lt;BR /&gt;1 1000 8 3 4&lt;BR /&gt;1 1000 8 1 2&lt;BR /&gt;1 0 24 5 6&lt;BR /&gt;1 0 24 1 2&lt;BR /&gt;1 2 24 7 8&lt;BR /&gt;1 2 24 1 2&lt;BR /&gt;1 0 48 4 5&lt;BR /&gt;1 0 48 1 2&lt;BR /&gt;1 2 48 6 5&lt;BR /&gt;1 2 48 1 2&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if there are two rows with same time and week, I am trying to replace the value1 and value 2 with different values.&lt;/P&gt;&lt;P&gt;Is there a way to achieve this output?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 15:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337002#M76463</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T15:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: replace value based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337010#M76464</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by time notsorted week notsorted;
if not first.week
then do;
  value1 = 0;
  value2 = 0;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2017 14:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337010#M76464</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-01T14:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: replace value based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337015#M76465</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;: Thanks, what if the values need to be replaced with values other than 0. I have updated the text to represent such a case. Is there a way to identify and specifically modify the first row (of the two rows with same time and week values)&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 15:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337015#M76465</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T15:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: replace value based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337039#M76478</link>
      <description>&lt;P&gt;In no way trying to solve your problem, more a remark of a general nature: your tables seem to be missing a identifying key. Even ID+time+week is not unique in your data. The lack of a so-called primary key is generally speaking a problem when solving this class of lookup puzzles. If there was such a key the solution would be perfectly simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 15:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337039#M76478</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-03-01T15:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: replace value based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337067#M76490</link>
      <description>&lt;P&gt;Not sure if the following meets your conditions, but should come close enough that you can adjust it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=i);
  set have;
  by time notsorted week notsorted;
  array used1(999) _temporary_;
  array used2(999) _temporary_;
  retain used1 used2;
  if first.week then do;
    i=0;
    call missing(of used1(*));
    call missing(of used2(*));
  end;
  i+1;
  if value1 not in used1 then used1(i)=value1;
  else do;
    value1=max(of used1(*))+ceil(100*rand("Uniform"));
    used1(i)=value1;
  end;
  if value2 not in used2 then used2(i)=value2;
  else do;
    value2=max(of used2(*))+ceil(100*rand("Uniform"));
    used2(i)=value2;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 16:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337067#M76490</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-01T16:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: replace value based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337259#M76575</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82839"&gt;@ari&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;: Thanks, what if the values need to be replaced with values other than 0. I have updated the text to represent such a case. Is there a way to identify and specifically modify the first row (of the two rows with same time and week values)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then we need to know from where to retrieve those replacement values.&lt;/P&gt;
&lt;P&gt;If you need to replace only the first line of a multiple of identical lines, I suggest&lt;/P&gt;
&lt;P&gt;- run a data step where you set a counter variable from _n_&lt;/P&gt;
&lt;P&gt;- sort the dataset by descending counter (you reverse the order completely)&lt;/P&gt;
&lt;P&gt;- use by as already suggetse in the next data step, and set your values only when last. and not first. of the last by variable is met&lt;/P&gt;
&lt;P&gt;- recreate the original order by sorting by counter; if you use out= in the proc sort to create a new dataset, you can drop counter there.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 08:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-value-based-on-condition/m-p/337259#M76575</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-02T08:04:22Z</dc:date>
    </item>
  </channel>
</rss>

