<?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 Update only the desired number of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820636#M323935</link>
    <description>Hi All!!&lt;BR /&gt;&lt;BR /&gt;I am trying to create a variable based on the values of another variable in the same dataset.&lt;BR /&gt;Dataset original has 137 records and after calculations and applying various conditions the values of the Variable FLAG are 1 and 0 the sum of Variable FLAG is 29. Now I am trying to create a new variable TOT_FLAG&lt;BR /&gt;Where the TOT_FLAG is only has the value 1 for 29 observations and 0 for the remaining 108 observations.&lt;BR /&gt;I have tried using the do until for some reason my code isn't updating only 29 observations.&lt;BR /&gt;&lt;BR /&gt;Please suggest.&lt;BR /&gt;&lt;BR /&gt;I'm not able to post the code now but will try again in sometime&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 28 Jun 2022 04:27:43 GMT</pubDate>
    <dc:creator>Santt0sh</dc:creator>
    <dc:date>2022-06-28T04:27:43Z</dc:date>
    <item>
      <title>Update only the desired number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820636#M323935</link>
      <description>Hi All!!&lt;BR /&gt;&lt;BR /&gt;I am trying to create a variable based on the values of another variable in the same dataset.&lt;BR /&gt;Dataset original has 137 records and after calculations and applying various conditions the values of the Variable FLAG are 1 and 0 the sum of Variable FLAG is 29. Now I am trying to create a new variable TOT_FLAG&lt;BR /&gt;Where the TOT_FLAG is only has the value 1 for 29 observations and 0 for the remaining 108 observations.&lt;BR /&gt;I have tried using the do until for some reason my code isn't updating only 29 observations.&lt;BR /&gt;&lt;BR /&gt;Please suggest.&lt;BR /&gt;&lt;BR /&gt;I'm not able to post the code now but will try again in sometime&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Jun 2022 04:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820636#M323935</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-06-28T04:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Update only the desired number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820639#M323938</link>
      <description>&lt;P&gt;Use _N_:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
tot_flag = (_n_ le 29);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jun 2022 05:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820639#M323938</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-28T05:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Update only the desired number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820681#M323959</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;Thank you for your quick response!!&lt;BR /&gt;&lt;BR /&gt;I'm sorry I forgot to mention that I need to update all the 29 observations out of 137 observations where another Variable "TRANSACTIONS" is 1&lt;BR /&gt;and the remaining 108 observations needs to be 0.&lt;BR /&gt;I was trying the below code, the issue seems to be with _N_ here&lt;BR /&gt;As it will only go till _N_ = 29 but I am trying to update the 29 observations where Transactions = 1 out of 137 observations, and the remaining 108 Flag needs to be assigned 0.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA Transactions;&lt;BR /&gt;Set Transactions;&lt;BR /&gt;If Transactions EQ 1 and _N_ LE 29 then do;&lt;BR /&gt;Total_Flag = 1;&lt;BR /&gt;END;&lt;BR /&gt;ELSE Do;&lt;BR /&gt;TOTAL_FLAG = 0;&lt;BR /&gt;END;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Kindly Suggest!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Jun 2022 12:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820681#M323959</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-06-28T12:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Update only the desired number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820696#M323968</link>
      <description>&lt;P&gt;So we can not use the data step iteration counter, but need to make our own:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain __n 1;
if __n lt 29 and transactions eq 1
then do;
  total_flag = 1;
  __n + 1;
end;
else total_flag = 0;
drop __n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jun 2022 14:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820696#M323968</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-28T14:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update only the desired number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820699#M323970</link>
      <description>Thank you Kurt!!!&lt;BR /&gt;I worked, to update all the 29 observations I had to change LT to LE.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Jun 2022 14:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-only-the-desired-number-of-observations/m-p/820699#M323970</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-06-28T14:44:14Z</dc:date>
    </item>
  </channel>
</rss>

