<?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: loop through rows/observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57797#M16123</link>
    <description>In oracle, I can say:&lt;BR /&gt;
&lt;BR /&gt;
for h in (select id from tbl where ....) loop&lt;BR /&gt;
...&lt;BR /&gt;
any processing needed for h.id, updating, deleting from other tables, sending notifications, aggregate data from other tables, etc. It essentially lets me do multiple and/or conditional data steps/sql blocks from within a data step.&lt;BR /&gt;
...&lt;BR /&gt;
end loop&lt;BR /&gt;
&lt;BR /&gt;
In SAS, you would have to (or at least the best way I've figured out how to):&lt;BR /&gt;
1. create a dataset tbl with a monotonic column (say rownum) using proc sql with monotonic() or a data step with the _N_ auto variable&lt;BR /&gt;
2. count how many rows where in the table and store it in a macro variable (say %totrows)&lt;BR /&gt;
3. build a macro to run a loop and use proc sql to get variables;&lt;BR /&gt;
...&lt;BR /&gt;
%do i = 1 to %totrows;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select id into :id from tbl where .... and rownum = &amp;amp;i;&lt;BR /&gt;
---&lt;BR /&gt;
any processing needed for that id&lt;BR /&gt;
...&lt;BR /&gt;
'%end;</description>
    <pubDate>Tue, 04 Jan 2011 23:40:17 GMT</pubDate>
    <dc:creator>DBailey</dc:creator>
    <dc:date>2011-01-04T23:40:17Z</dc:date>
    <item>
      <title>loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57788#M16114</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I need the same functionality as cursors on SQL servers. Is it possible in SAS?&lt;BR /&gt;
Basically I want iterate through dataset and in each iteration I want to access the variables on particular row. &lt;BR /&gt;
Can someone post here some simple solution?&lt;BR /&gt;
&lt;BR /&gt;
Thank's in advance</description>
      <pubDate>Mon, 03 Jan 2011 13:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57788#M16114</guid>
      <dc:creator>Julo</dc:creator>
      <dc:date>2011-01-03T13:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57789#M16115</link>
      <description>Hi:&lt;BR /&gt;
  I'm not exactly sure what 'cursors' does in SQL or what you are trying to achieve with cursors. Can you post some code that uses cursors, or better, describe your data and what it is you need to do?&lt;BR /&gt;
&lt;BR /&gt;
  I do note that in the documentation:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#a001371529.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#a001371529.htm&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  There is a statement about the CURSOR_TYPE= dataset option that&lt;BR /&gt;
"Not all drivers support all cursor types. An error is returned if the specified cursor type is not supported."  So, if you are using SAS/Access for a relational database, you might find the CURSOR_TYPE dataset option useful to investigate. &lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 03 Jan 2011 16:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57789#M16115</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-03T16:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57790#M16116</link>
      <description>...&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; I need the same functionality as cursors on SQL&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; servers. Is it possible in SAS?&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; Basically I want iterate through dataset and in each&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; iteration I want to access the variables on&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; particular row. &lt;BR /&gt;&lt;BR /&gt;
...&lt;BR /&gt;&lt;BR /&gt;
Is it &lt;I&gt;possible&lt;/I&gt; in SAS?! You are kidding, right? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Data step &lt;I&gt;is&lt;/I&gt; for iterating over observations. A simple data step with a set statement is rather exactly like using a forward (only) cursor without much fuss (iteration is built in):&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;data&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;_null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;sashelp.class;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;sex&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#800080;font-family:Courier New;font-size:10pt;"&gt;"M"&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;name=&amp;nbsp;age=&amp;nbsp;sex=;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;on&amp;nbsp;log&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Alfred&amp;nbsp;Age=14&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Henry&amp;nbsp;Age=14&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=James&amp;nbsp;Age=12&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Jeffrey&amp;nbsp;Age=13&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=John&amp;nbsp;Age=12&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Philip&amp;nbsp;Age=16&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Robert&amp;nbsp;Age=12&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Ronald&amp;nbsp;Age=15&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=Thomas&amp;nbsp;Age=11&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name=William&amp;nbsp;Age=15&amp;nbsp;Sex=M&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2011 21:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57790#M16116</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-01-03T21:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57791#M16117</link>
      <description>Dear Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Basically using cursors you can iterate observations one by one and access each object separately.&lt;BR /&gt;
For example you have the table with columns (Name, Heigth, Weight) and some sample data&lt;BR /&gt;
Joe    175  70&lt;BR /&gt;
Linda 162  55&lt;BR /&gt;
Lucy  172  66&lt;BR /&gt;
&lt;BR /&gt;
and i need to access each line such as below:&lt;BR /&gt;
FOR I = 0 to DATASET.LINESCOUNT&lt;BR /&gt;
    DATASET(I).Height ...etc&lt;BR /&gt;
END FOR&lt;BR /&gt;
So in each iteration i can access one line. The advantage is, that you can do any complicated calculations which cannot be done by sas functions. Disadvantage is poor performance.&lt;BR /&gt;
&lt;BR /&gt;
When you look at this example &lt;A href="http://www.sqlteam.com/article/cursors-an-overview" target="_blank"&gt;http://www.sqlteam.com/article/cursors-an-overview&lt;/A&gt;&lt;BR /&gt;
Here is the usage of cursor on microsoft sql server. In each iteration (WHILE loop), the value in row is stored to variable @AuthorID. Of course there can be more then one value. And this is what I need.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any ideas</description>
      <pubDate>Tue, 04 Jan 2011 07:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57791#M16117</guid>
      <dc:creator>Julo</dc:creator>
      <dc:date>2011-01-04T07:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57792#M16118</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for reply, I am not kidding. I am sql/.net developer forced to work with sas and a lot of routine operations which I was used to work with, doesn't work in sas.&lt;BR /&gt;
&lt;BR /&gt;
It is nice, that iteration is built in, but i need to access each variable in row/obseravation separately and make computation over it. Please see the post I have replied to Cynthia. There is exactly what I would like to do.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 04 Jan 2011 07:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57792#M16118</guid>
      <dc:creator>Julo</dc:creator>
      <dc:date>2011-01-04T07:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57793#M16119</link>
      <description>It looks like you need SAS " array{*} " statement.</description>
      <pubDate>Tue, 04 Jan 2011 09:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57793#M16119</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-04T09:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57794#M16120</link>
      <description>It sounds like you're looking for the &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000173782.htm" target="_blank"&gt;POINT= option on the SET statement&lt;/A&gt;.</description>
      <pubDate>Tue, 04 Jan 2011 13:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57794#M16120</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2011-01-04T13:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57795#M16121</link>
      <description>Julo,&lt;BR /&gt;
&lt;BR /&gt;
I think that Cynthia put you in the right direction already.  I'm sure that you'll have to do a number of Google searches to find all of the info you want, but another place to start might be:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/tools/oledb/app_cursorlocktypes.htm" target="_blank"&gt;http://support.sas.com/documentation/tools/oledb/app_cursorlocktypes.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Tue, 04 Jan 2011 13:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57795#M16121</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-01-04T13:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57796#M16122</link>
      <description>Out of curiousity what type of process would a SQL cursor implemented in SAS be more efficient than a SAS datastep?</description>
      <pubDate>Tue, 04 Jan 2011 19:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57796#M16122</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-01-04T19:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57797#M16123</link>
      <description>In oracle, I can say:&lt;BR /&gt;
&lt;BR /&gt;
for h in (select id from tbl where ....) loop&lt;BR /&gt;
...&lt;BR /&gt;
any processing needed for h.id, updating, deleting from other tables, sending notifications, aggregate data from other tables, etc. It essentially lets me do multiple and/or conditional data steps/sql blocks from within a data step.&lt;BR /&gt;
...&lt;BR /&gt;
end loop&lt;BR /&gt;
&lt;BR /&gt;
In SAS, you would have to (or at least the best way I've figured out how to):&lt;BR /&gt;
1. create a dataset tbl with a monotonic column (say rownum) using proc sql with monotonic() or a data step with the _N_ auto variable&lt;BR /&gt;
2. count how many rows where in the table and store it in a macro variable (say %totrows)&lt;BR /&gt;
3. build a macro to run a loop and use proc sql to get variables;&lt;BR /&gt;
...&lt;BR /&gt;
%do i = 1 to %totrows;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select id into :id from tbl where .... and rownum = &amp;amp;i;&lt;BR /&gt;
---&lt;BR /&gt;
any processing needed for that id&lt;BR /&gt;
...&lt;BR /&gt;
'%end;</description>
      <pubDate>Tue, 04 Jan 2011 23:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57797#M16123</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-01-04T23:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57798#M16124</link>
      <description>...&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; In SAS, you would have to (or at least the best way&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; I've figured out how to):&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; 1. create a dataset tbl with a monotonic column (say&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; rownum) using proc sql with monotonic() or a data&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; step with the _N_ auto variable&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; 2. count how many rows where in the table and store&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; it in a macro variable (say %totrows)&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; 3. build a macro to run a loop and use proc sql to&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; get variables;&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; ...&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; %do i = 1 to %totrows;&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; proc sql;&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; select id into :id from tbl where .... and rownum =&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; &amp;amp;i;&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; ---&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; any processing needed for that id&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; ...&lt;BR /&gt;&lt;BR /&gt;
&amp;gt; '%end;&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
:-)</description>
      <pubDate>Wed, 05 Jan 2011 15:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57798#M16124</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-01-05T15:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57799#M16125</link>
      <description>I'm not sure if I'm missing something here on what you want to do but we use cursors in oracle/sql and I have not seen anything so complicated that a SAS data step cannot accomplish the same thing.  &lt;BR /&gt;
&lt;BR /&gt;
The data step inputs a single record, acts upon the objects (vars) of that record and then outpts that record. It then retrieves the next record, (if there is one) and repeats the process.&lt;BR /&gt;
&lt;BR /&gt;
In your explanation:&lt;BR /&gt;
&lt;BR /&gt;
FOR I = 0 to DATASET.LINESCOUNT&lt;BR /&gt;
DATASET(I).Height ...etc&lt;BR /&gt;
END FOR&lt;BR /&gt;
&lt;BR /&gt;
The data step equivelent is&lt;BR /&gt;
    data example;&lt;BR /&gt;
       set example;&lt;BR /&gt;
       height = .......;&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
The for/end for is implied in the data step.  The specific line can be reference by automatic variable (linescount= _n_;&lt;BR /&gt;
 &lt;BR /&gt;
This will iterate through each row of your example table and perform whatever operation you want on height.  This is very simplified but you could get pretty complex in what you do with that observation.  &lt;BR /&gt;
&lt;BR /&gt;
Of course it would have been helpful if an  example of what exactly you do with sql/cursor was provided.  What specific operations that you "used to work with, doesn't work in sas".</description>
      <pubDate>Thu, 06 Jan 2011 16:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57799#M16125</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2011-01-06T16:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57800#M16126</link>
      <description>Hi LAP,&lt;BR /&gt;
&lt;BR /&gt;
Thanks - i had no idea about referencing specific line. I have solved my problem using proc iml, but better (or more clear) solution is to use data step.&lt;BR /&gt;
&lt;BR /&gt;
For example - if i want to make a sum of height variable from my previous example.&lt;BR /&gt;
INT SUM = 0;. &lt;BR /&gt;
FOR I = 0 to DATASET.LINESCOUNT&lt;BR /&gt;
SUM = SUM + DATASET(I).Height.&lt;BR /&gt;
END FOR&lt;BR /&gt;
&lt;BR /&gt;
How can I do this in data step? Declare variable (not column in table) out of the data step.&lt;BR /&gt;
&lt;BR /&gt;
sum = 0;&lt;BR /&gt;
data example;&lt;BR /&gt;
set example;&lt;BR /&gt;
sum = sum + height&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Please do not answer something like : use sum function over height column &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
This is only an example, the calculation will be more complex.</description>
      <pubDate>Mon, 10 Jan 2011 09:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57800#M16126</guid>
      <dc:creator>Julo</dc:creator>
      <dc:date>2011-01-10T09:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57801#M16127</link>
      <description>when IML can solve your problem, it will probably be more effective than a data step when you want differing calculations down different subsets and different columns, because iml allows you to load the whole table into an array (matrix). Syntax and processing refer only to the copy in memory. So that is also the limitation of the IML approach - Some data sets will be too big for memory (unless you are very very well resourced - not many of us have memory for a 100gb matrix) .&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Mon, 10 Jan 2011 12:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57801#M16127</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-10T12:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57802#M16128</link>
      <description>&amp;gt; How can I do this in data step? Declare variable (not&lt;BR /&gt;
&amp;gt; column in table) out of the data step.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; sum = 0;&lt;BR /&gt;
&amp;gt; data example;&lt;BR /&gt;
&amp;gt; set example;&lt;BR /&gt;
&amp;gt; sum = sum + height&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
* not complex to place a set statement within a do loop terminating when there is no more data provided by that set statement&lt;BR /&gt;
data ........... ;&lt;BR /&gt;
 ..........&lt;BR /&gt;
  sum=0 ;&lt;BR /&gt;
  do while( not end_of_this );&lt;BR /&gt;
     set example(where=( relevant where clause)) end= end_of_this ;&lt;BR /&gt;
     sum+height ;&lt;BR /&gt;
  end ;&lt;BR /&gt;
............&lt;BR /&gt;
........&lt;BR /&gt;
 stop ;&lt;BR /&gt;
run;&lt;BR /&gt;
of course then the data step iteration needs to be managed carefully and you'll probably find need for the STOP statement when appropriate;</description>
      <pubDate>Mon, 10 Jan 2011 12:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57802#M16128</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-10T12:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57803#M16129</link>
      <description>Why have the sum declared outside the datastep? &lt;BR /&gt;
&lt;BR /&gt;
Its easy to solve the problems you're proposing, but then you say it might be more complex so without you being clear enough it's kind of a moot point.  &lt;BR /&gt;
&lt;BR /&gt;
A random guess into what you're doing looks like BY processing with RETAIN statements needed to calculate some kind of running total, but if you don't provide a more clear example of what you have and what you want its almost impossible to help you.

The following may help. &lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi31/246-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/246-31.pdf&lt;/A&gt;&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Reeza</description>
      <pubDate>Mon, 10 Jan 2011 17:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57803#M16129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-01-10T17:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57804#M16130</link>
      <description>&lt;P&gt;If I'm understanding what you want: sum some value across all rows in you table.&lt;BR /&gt; &lt;BR /&gt; then I think this will work.&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
set example;
if _n_ = 1 then sum=0; *I do not think you need this line but I put in for example;

sum + height; increments sum by value of height; 

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt; &lt;BR /&gt; I'm not sure of what you are thinking about when you say use sum function over height column. The sum function works on columns in a single row ie&lt;BR /&gt; something like this.... sum = sum(ht1, ht2, ht3). &lt;BR /&gt; &lt;BR /&gt; This syntax sums across rows. So when i = linescount, Height will be the sum of height over all lines. &lt;BR /&gt; &lt;BR /&gt; You certainly can get more creative with what you increment - as you say some more complex calculation&lt;BR /&gt; &lt;BR /&gt; for example : sum + (a + b*(c^2)*d/e); where a-e are all columns.&lt;BR /&gt; &lt;BR /&gt; Hope this helps&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 20:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/57804#M16130</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2016-09-27T20:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: loop through rows/observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/313758#M61513</link>
      <description>&lt;P&gt;Can you please advise how one can output the contents of the PDV for each iteration as one steps through a SAS Program in order to validate the logic on a test case?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 12:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-through-rows-observations/m-p/313758#M61513</guid>
      <dc:creator>JonDickens1607</dc:creator>
      <dc:date>2016-11-23T12:26:12Z</dc:date>
    </item>
  </channel>
</rss>

