<?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: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553686#M153986</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271757"&gt;@Abhiraj&lt;/a&gt;&amp;nbsp; Sure one of us will provide the solution. However may i ask why the weird data structure with blank values for by groups. I am increasingly concerned to have such a structure in a production environment or to have a meaningful analysis for the matter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2019 15:46:03 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-04-24T15:46:03Z</dc:date>
    <item>
      <title>PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553660#M153975</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a small problem which I tried to solve but got stuck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created the following data set -&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data car;
infile datalines dsd;
input brand $ loan ;
datalines;
mini,70
,30
,20
,10
toyota,80
,40
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 321px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28984i0040DAE2AAB970E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;f&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two variables - brand and loan.&lt;/P&gt;&lt;P&gt;what i need to do is in first observation of each brand, loan variable should show only outstanding loan amount.&lt;/P&gt;&lt;P&gt;for example - for brand mini in first observation, output should be - mini&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;70-(30+20+10) = 10, and rest all observations remaining same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EXPECTED FULL OUTPUT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;brand&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;loan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;mini&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;Toyota&amp;nbsp; &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I NEED TO DO THIS USING DO LOOP.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553660#M153975</guid>
      <dc:creator>Abhiraj</dc:creator>
      <dc:date>2019-04-24T14:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553680#M153981</link>
      <description>&lt;P&gt;Hi and welcome to the SAS Communities&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us your code so far? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 15:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553680#M153981</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-04-24T15:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553682#M153983</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
do i = 1 to 2;
set car nobs=k;
if brand eq '' then total+loan;
if brand ne '' then total = 0;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Tried this. but it is wrong i know!!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 15:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553682#M153983</guid>
      <dc:creator>Abhiraj</dc:creator>
      <dc:date>2019-04-24T15:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553684#M153984</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271757"&gt;@Abhiraj&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a small problem which I tried to solve but got stuck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created the following data set -&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data car;
infile datalines dsd;
input brand $ loan ;
datalines;
mini,70
,30
,20
,10
toyota,80
,40
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 321px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28984i0040DAE2AAB970E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;f&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two variables - brand and loan.&lt;/P&gt;
&lt;P&gt;what i need to do is in first observation of each brand, loan variable should show only outstanding loan amount.&lt;/P&gt;
&lt;P&gt;for example - for brand mini in first observation, output should be - mini&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;70-(30+20+10) = 10, and rest all observations remaining same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EXPECTED FULL OUTPUT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;brand&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;loan&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;mini&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;Toyota&amp;nbsp; &amp;nbsp; 40&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I NEED TO DO THIS USING DO LOOP.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How do we know what the initial value of the loan is? Outstanding loan amount?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should include all identification variables in EVERY record. You create unneeded complications by not having "mini" or "Toyota" on all of the records related to each.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Conceptually an initial value of a loan and a loan payment are different things and likely should be different variables as any thing that changes the order of your data means that you are likely not to be able to identify the "initial value".&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 15:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553684#M153984</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-24T15:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553686#M153986</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271757"&gt;@Abhiraj&lt;/a&gt;&amp;nbsp; Sure one of us will provide the solution. However may i ask why the weird data structure with blank values for by groups. I am increasingly concerned to have such a structure in a production environment or to have a meaningful analysis for the matter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 15:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553686#M153986</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-24T15:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553687#M153987</link>
      <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;this is the assignment given to me. I know data is weird but cant help with that&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 15:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553687#M153987</guid>
      <dc:creator>Abhiraj</dc:creator>
      <dc:date>2019-04-24T15:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553700#M153995</link>
      <description>&lt;P&gt;Ok Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271757"&gt;@Abhiraj&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try--&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data car;
infile datalines dsd;
input brand $ loan ;
datalines;
mini,70
,30
,20
,10
toyota,80
,40
;
run;

data want;
set car;
if brand&amp;gt;' ' then do;
do i=_n_+1 to nobs  ;
set car(rename=(brand=_brand loan=_loan)) nobs=nobs point=i;
if brand ne _brand and _brand&amp;gt;' ' then leave;
_s=sum(_s,_loan);
end;
loan=loan-_s;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 16:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553700#M153995</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-24T16:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553879#M154060</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;.. It works.. I couldnt understand what multiple set statements do in a single data step...&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 07:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553879#M154060</guid>
      <dc:creator>Abhiraj</dc:creator>
      <dc:date>2019-04-25T07:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553940#M154076</link>
      <description>&lt;P&gt;Basically in this instance it does a Self join/merge one to many to satisfy your conditions to compute sum. There are so many articles online you can find about the use of multiple set statements in a datastep for joins/merges/look ups etc. That's how I learned. Have fun!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 12:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553940#M154076</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-25T12:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROBLEM - CANT GET A DESIRED OUTPUT - DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553963#M154088</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data car;
infile datalines dsd;
input brand $ loan ;
datalines;
mini,70
,30
,20
,10
toyota,80
,40
;
run;
data have;
 set car;
 if not missing(brand) then group+1;
run;
data want;
sum=0;
 do until(last.group);
  set have;
  by group;
  if not first.group then sum+loan;
 end;

 do until(last.group);
  set have;
  by group;
  if first.group then loan=loan-sum;
  output;
 end;
 drop sum group;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Apr 2019 13:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROBLEM-CANT-GET-A-DESIRED-OUTPUT-DO-LOOP/m-p/553963#M154088</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-25T13:56:53Z</dc:date>
    </item>
  </channel>
</rss>

