<?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: re Replace value within ID if condition satisfied DESCRIPTION =: 'Intnal'; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/495101#M130605</link>
    <description>&lt;P&gt;Hi Chris.....yes it makes sense and your right there are duplicates. The data is actually accounting data where the description field may have the same entries such as Tuition Payment where the student may have made tuition payments as installment payment on&amp;nbsp;different dates so there would be multiple records to record each of the payments as Tuition Payment.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Sep 2018 00:22:04 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2018-09-13T00:22:04Z</dc:date>
    <item>
      <title>re Replace value within ID if condition satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/494676#M130401</link>
      <description>&lt;P&gt;Hi.....I am trying to replace the entry of "International" in the description field if there is an entry of either 'Intnal - BAA', 'Intnal - CA', 'Intnal - AM'&amp;nbsp;or 'Intnal - MOA' appears for the same ID with either&amp;nbsp;'Business Administrative Assistant', 'Carpentry', 'Auto Mechanics' or 'Medical Office Assistant'. Any suggestions...thanks in adavance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id description;
cards;
1 International
1 Seat Deposit
1 Intnal - BAA
2 International
2 Admin Fee
2 Seat Deposit
2 Intnal - CA
3 International
3 Intnal – AM
4 International
4 Admin Fee
4 Seat Deposit
4 Lab Fee
4 Text Book
4 Intnal - MAA
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 Business Administrative Assistant&lt;/P&gt;
&lt;P&gt;1 Seat Deposit&lt;/P&gt;
&lt;P&gt;1 Intnal - BAA&lt;/P&gt;
&lt;P&gt;2 Carpentry&lt;/P&gt;
&lt;P&gt;2 Admin Fee&lt;/P&gt;
&lt;P&gt;2 Seat Deposit&lt;/P&gt;
&lt;P&gt;2 Intnal - CA&lt;/P&gt;
&lt;P&gt;3 Auto Mechanics&lt;/P&gt;
&lt;P&gt;3 Intnal – AM&lt;/P&gt;
&lt;P&gt;4 Medical Office Assistant&lt;/P&gt;
&lt;P&gt;4 Admin Fee&lt;/P&gt;
&lt;P&gt;4 Seat Deposit&lt;/P&gt;
&lt;P&gt;4 Lab Fee&lt;/P&gt;
&lt;P&gt;4 Text Book&lt;/P&gt;
&lt;P&gt;4 Intnal - MOA&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 23:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/494676#M130401</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2018-09-11T23:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: re Replace value within ID if condition satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/494679#M130402</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input ID DESCRIPTION :&amp;amp; $50.;
cards;
1 International
1 Seat Deposit
1 Intnal - BAA
2 International
2 Admin Fee
2 Seat Deposit
2 Intnal - CA
3 International
3 Intnal - AM 
4 International
4 Admin Fee
4 Seat Deposit
4 Lab Fee
4 Text Book
4 Intnal - MOA
run;
data _F;
  retain TYPE 'N' FMTNAME 'map'; 
  set HAVE;
  where DESCRIPTION =: 'Intnal';
  START=ID; LABEL=DESCRIPTION;
  if ID ne lag(ID);
run;
proc format cntlin=_F; 
  value $remap 'Intnal - BAA' ='Business Administrative Assistant'
               'Intnal - CA ' ='Carpentry'
               'Intnal - AM ' ='Auto Mechanics'
               'Intnal - MOA' ='Medical Office Assistant';
run;
data WANT;
  set HAVE;
  if DESCRIPTION='International' then DESCRIPTION=put(put(ID,map. -l),$remap.);
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;DESCRIPTION&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Business Administrative Assistant&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Seat Deposit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Intnal - BAA&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;Carpentry&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;Admin Fee&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;Seat Deposit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;Intnal - CA&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;Auto Mechanics&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;Intnal - AM&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;Medical Office Assistant&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;Admin Fee&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;Seat Deposit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;Lab Fee&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;Text Book&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;Intnal - MOA&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Sep 2018 00:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/494679#M130402</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-12T00:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: re Replace value within ID if condition satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/494834#M130478</link>
      <description>&lt;P&gt;Hi Chris....thanks for your suggestion. I tried your suggestion and I am getting the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: For format MAP, this range is repeated, or values overlap: 157796-157796.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 13:25:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/494834#M130478</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2018-09-12T13:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: re Replace value within ID if condition satisfied DESCRIPTION =: 'Intnal';</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/495066#M130596</link>
      <description>&lt;P&gt;It probably means that the same ID appears twice in table _F, which means that the input table is not&amp;nbsp;grouped by ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assumed that the IDs were grouped, and that there could only be one "job" for each in case of replacement of the international values (there is no&amp;nbsp;exception flagging for multiple values in the code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If it's just a matter of duplicate ID with the same "job" mapping (because IDs were not grouped in the original file), you can simply deduplicate table _F&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. If the same ID maps to multiple jobs (and again I do not flag this in the code), you also need to deduplicate by ID, and pick one the the "jobs".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The line&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;lag&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;keeps only one row for each ID if they are grouped together.&lt;/P&gt;
&lt;P&gt;If they are not grouped, you need to do this task as an additional step.&lt;/P&gt;
&lt;P&gt;Note that if this test ever used, it means that multiple IDs had &lt;FONT face="courier new,courier"&gt;DESCRIPTION =: 'Intnal'&amp;nbsp;&lt;/FONT&gt; , in which case one might want to look at whether they map to the same "job" (the test just keeps the first one found).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this make sense?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 22:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/495066#M130596</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-12T22:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: re Replace value within ID if condition satisfied DESCRIPTION =: 'Intnal';</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/495101#M130605</link>
      <description>&lt;P&gt;Hi Chris.....yes it makes sense and your right there are duplicates. The data is actually accounting data where the description field may have the same entries such as Tuition Payment where the student may have made tuition payments as installment payment on&amp;nbsp;different dates so there would be multiple records to record each of the payments as Tuition Payment.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 00:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Replace-value-within-ID-if-condition-satisfied/m-p/495101#M130605</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2018-09-13T00:22:04Z</dc:date>
    </item>
  </channel>
</rss>

