<?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: Looping through rows of table in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756287#M30060</link>
    <description>Thank you!</description>
    <pubDate>Fri, 23 Jul 2021 18:32:03 GMT</pubDate>
    <dc:creator>jlin4</dc:creator>
    <dc:date>2021-07-23T18:32:03Z</dc:date>
    <item>
      <title>Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756267#M30053</link>
      <description>&lt;P&gt;Hi, supposed I have a list of IDs, presented in the form of a table, like work.id. For each ID, I wish to perform a set of operations that will return me either a "Y" or a "N". After which, I would like to add the returns to the table as a new column, such as in work.id_response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May I enquire how should I go about doing so? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.id;
input id$;
cards;
abc
def
ghi
jkl
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.id_response;
input id$ response$;
cards;
abc y
def y
ghi n
jkl n
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756267#M30053</guid>
      <dc:creator>jlin4</dc:creator>
      <dc:date>2021-07-23T17:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756269#M30054</link>
      <description>&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set id;
    if condition=1 /* You need to type the real condition being tested*/ then response='Y'; 
    else response='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that the default behavior of a data step is to loop over all observations, so you don't need to program any loop.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756269#M30054</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-23T17:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756270#M30055</link>
      <description>&lt;P&gt;Depends on the "set of operations" needed in that step. If it's something as simple as checking if it's in a list of value a data step works fine. If you need to go look up something in three different table and factor in amounts over time that's a lot more complex. &lt;BR /&gt;&lt;BR /&gt;Your use case is too simplistic to provide an answer &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is an example of your simplistic case - SAS loops automatically through each row in a data set so no explicit loop or anything else is required.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set id;
if id in ('abc', 'def') then response = "y";
else response = "n";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358095"&gt;@jlin4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, supposed I have a list of IDs, presented in the form of a table, like work.id. For each ID, I wish to perform a set of operations that will return me either a "Y" or a "N". After which, I would like to add the returns to the table as a new column, such as in work.id_response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I enquire how should I go about doing so? Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.id;
input id$;
cards;
abc
def
ghi
jkl
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.id_response;
input id$ response$;
cards;
abc y
def y
ghi n
jkl n
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756270#M30055</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-23T17:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756271#M30056</link>
      <description>&lt;P&gt;What are the rules for adding "y" or "n"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step "loops through rows" of a data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This adds a row number (actual loop count) to your data from the work.id dataset.&lt;/P&gt;
&lt;PRE&gt;data work.id_row;
   set work.id;
   row = _n_;
run;&lt;/PRE&gt;
&lt;P&gt;_n_ is an automatic variable that SAS creates as it counts how many times the data step executes, i.e. "loops".&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756271#M30056</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-23T17:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756286#M30059</link>
      <description>thank you!</description>
      <pubDate>Fri, 23 Jul 2021 18:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756286#M30059</guid>
      <dc:creator>jlin4</dc:creator>
      <dc:date>2021-07-23T18:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756287#M30060</link>
      <description>Thank you!</description>
      <pubDate>Fri, 23 Jul 2021 18:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756287#M30060</guid>
      <dc:creator>jlin4</dc:creator>
      <dc:date>2021-07-23T18:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through rows of table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756312#M30067</link>
      <description>If one of the responses here is the correct answer to your question please mark it as resolved.</description>
      <pubDate>Fri, 23 Jul 2021 20:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Looping-through-rows-of-table/m-p/756312#M30067</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-23T20:26:17Z</dc:date>
    </item>
  </channel>
</rss>

