<?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: Need to format the raws with different values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255714#M48890</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id	sys_amount	actual_amount;
cards;
100 50 100
100 50 100
200 20 40
200 20 40
150 100 100	
800 25 56
;
run;
proc sql;
create table want(drop=sum n) as
 select *,sum(sys_amount) as sum,count(*) as n,
  case when calculated n=2 and calculated sum=actual_amount then 'B'
       when calculated n=1 and calculated sum=actual_amount then 'N'
       when calculated n=1 and calculated sum ne actual_amount then 'R'
  end as format
  from have
   group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Mar 2016 02:46:31 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-03-10T02:46:31Z</dc:date>
    <item>
      <title>Need to format the raws with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255573#M48819</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got one request recently . It looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;sys_amount&lt;/TD&gt;&lt;TD&gt;actual_amount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example if the id 100 and for that we have 2 sys_amount and actual amouunt as 100 which is 100 (50+50) i need to create one extra column and need to highlight as "B"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reqults should be like below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;sys_amount&lt;/TD&gt;&lt;TD&gt;actual_amount&lt;/TD&gt;&lt;TD&gt;format&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;TD&gt;56&lt;/TD&gt;&lt;TD&gt;R&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example if we have same id and and if we summarize the sys_amount if we are getting the amount in the actual amount the the format should be B and if the sys_amount and actual_amount is same format should be N like wise ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me on this&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 16:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255573#M48819</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2016-03-09T16:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need to format the raws with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255590#M48830</link>
      <description>&lt;P&gt;So are these definitions correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B = more than 1 record for the ID, and total of all SYS_AMOUNT is equal to ACTUAL_AMOUNT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;N = just 1 record for the ID, and SYS_AMOUNT equals ACTUAL_AMOUNT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;R = just 1 record for the ID, and SYS_AMOUNT does not equal ACTUAL_AMOUNT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming these definitions are correct, here are a few more cases that need some definition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;?? = more than 1 record for the ID, and the ACTUAL_AMOUNT values change (some equal to the total SYS_AMOUNT, some not equal)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;?? = just 1 record for the ID, and the SYS_AMOUNT equals ACTUAL_AMOUNT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not hard to program.&amp;nbsp; It's more difficult to figure out the rules.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 17:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255590#M48830</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-09T17:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need to format the raws with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255596#M48836</link>
      <description>&lt;P&gt;Hi the below definition you provided is correct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B = more than 1 record for the ID, and total of all SYS_AMOUNT is equal to ACTUAL_AMOUNT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;N = just 1 record for the ID, and SYS_AMOUNT equals ACTUAL_AMOUNT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R = just 1 record for the ID, and SYS_AMOUNT does not equal ACTUAL_AMOUNT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are multiple ids then sys_amount and Actual_amount will be equal always .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only need to get the above three rules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 17:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255596#M48836</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2016-03-09T17:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need to format the raws with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255607#M48843</link>
      <description>&lt;P&gt;In my opinion, it would be a serious error to rely on the data always containing what you expect.&amp;nbsp; I will define a couple of additional categories:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;R = just 1 record for the ID, and the SYS_AMOUNT does not equal ACTUAL_AMOUNT (as in your sample data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X = multiple records for the ID, and the SYS_AMOUNT does not equal the ACTUAL_AMOUNTs&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe these values will never be needed.&amp;nbsp; But they should be accounted for in the programming logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, it is possible that multiple values can be assigned for the same ID, if the amounts change within that ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a program you can work with.&amp;nbsp; It assumes your data set is sorted by ID, so you may need to sort it first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;calculated_total = 0;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; calculated_total + sys_amount;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if calculated_total = actual_amount then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.id=0 or last.id=0 then format='B';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else format='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.id=0 or last.id=0 then format='X';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else format='R';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always change the assignments if you want a different set of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 18:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255607#M48843</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-09T18:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need to format the raws with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255714#M48890</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id	sys_amount	actual_amount;
cards;
100 50 100
100 50 100
200 20 40
200 20 40
150 100 100	
800 25 56
;
run;
proc sql;
create table want(drop=sum n) as
 select *,sum(sys_amount) as sum,count(*) as n,
  case when calculated n=2 and calculated sum=actual_amount then 'B'
       when calculated n=1 and calculated sum=actual_amount then 'N'
       when calculated n=1 and calculated sum ne actual_amount then 'R'
  end as format
  from have
   group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Mar 2016 02:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-format-the-raws-with-different-values/m-p/255714#M48890</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-10T02:46:31Z</dc:date>
    </item>
  </channel>
</rss>

