<?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: Read Data Set through Do Loop. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78493#M16968</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not tested code;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt; do until(last);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; n+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;put n=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jul 2013 08:41:51 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2013-07-15T08:41:51Z</dc:date>
    <item>
      <title>Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78492#M16967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is that possible to read one by one observation from a data set through Do Loop?&lt;/P&gt;&lt;P&gt;My requirement is to traverse through the observations of the data set using loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you:)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 03:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78492#M16967</guid>
      <dc:creator>Chikku</dc:creator>
      <dc:date>2013-07-15T03:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78493#M16968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not tested code;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt; do until(last);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; n+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;put n=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 08:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78493#M16968</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-15T08:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78494#M16969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i'm not sure if this is what you're looking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(*) into :observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.class;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;observations;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.class (firstobs=&amp;amp;i obs=&amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog "Loop: &amp;amp;i do something";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%loop;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 08:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78494#M16969</guid>
      <dc:creator>Domenico</dc:creator>
      <dc:date>2013-07-15T08:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78495#M16970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't understand.&amp;nbsp; SAS reads and processes the observations sequentially in a datastep, so there is no need for a do loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I missing something here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 09:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78495#M16970</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-15T09:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78496#M16971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sometimes you need to complete your homework per the instructions...:)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sometimes you need to open a dataset and iterate through the observations performing other functions on each row.&amp;nbsp; I don't think you can do this within a data step.&amp;nbsp; You can simulate a cursor within a macro statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro M1(dataset);&lt;/P&gt;&lt;P&gt;%local dsid rc now;&lt;/P&gt;&lt;P&gt;%let dsid = %sysfunc(open(dataset));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do %while (%sysfunc(fetch(&amp;amp;dsid)) = 0); /* outer loop across rows;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%end; /*while fetch loop*/&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use getvarn or getvarc to retrieve values the current row of &amp;amp;dsid but you have to wrap them in %sysfunc().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 13:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78496#M16971</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-07-15T13:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78497#M16972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you might be right about the homework to be honest.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I use OPEN And CLOSE frequently when I want to identify the number of OBS in a dataset, but I have never used FETCH.&amp;nbsp; I can see the benefits to create a Macro variable, but can you use these to write back to a dataset?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 02:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78497#M16972</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-16T02:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78498#M16973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro functions cannot create or write to a SAS data set. Veryify this by looking in the&amp;nbsp; language documentation at the options available for the open() function&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 07:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78498#M16973</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-16T07:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78499#M16974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Scott,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As an example as to why this can be useful from personal experience.&amp;nbsp; I've had to do a levenstein (complev) between all words of a "dictionary" and all words in a given column of a gigantic dataset. Building a proc FCMP taking a character array _TEMPORARY_ as a parameter (the dictionary) allowed me to do so in a single data step with very effective processing speed. In order to pass the said dictionary to the proc FCMP, I needed to do such a do loop on the dictionary dataset to load it in an array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 12:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78499#M16974</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-07-16T12:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78500#M16975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Intriguing Vincent.&amp;nbsp; I look forward to having an opportunity to do that in the future.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 14:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78500#M16975</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-16T14:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78501#M16976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPEN, CLOSE, and FETCH are not solely MACRO functions.&amp;nbsp; They can also be used within a datastep,as per below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA MYDATA;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* CREATE VARIABLES FOR ASSIGNMENT */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*BY CALL SET */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; LENGTH NAME $8 SEX $1 AGE WEIGHT HEIGHT 8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DROP RC DSID;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DSID=OPEN("SASHELP.CLASS","I");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CALL SET (DSID);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DO I=1 TO 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RC=FETCHOBS(DSID,I);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OUTPUT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 22:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78501#M16976</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-16T22:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78502#M16977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;P&gt;Of course you are correct.&lt;/P&gt;&lt;P&gt;What I should have pointed out is that OPEN() in the context requested provides only the functionality of the the data step environment through %SYSFUNC() and although the SAS/SCL environment provides a similar function which does support UPDATE and (iirc) NEW these open modes were not ported to the base SAS&amp;nbsp; environment along with several other SCL-type functions (way back in SAS release 6.09e days).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which is a long winded way of saying &lt;/P&gt;&lt;P&gt;Answer your own question&lt;/P&gt;&lt;P&gt;Read the documentation for OPEN()&amp;nbsp; - there is no WRITE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Should the WRITE mode be needed, learn and use SAS/SCL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 05:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78502#M16977</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-07-17T05:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78503#M16978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Peter.&amp;nbsp; It is nice to hear about the history of these functions.&amp;nbsp; I only started with V8 and although I feel as though I have a decent grip on things, I certainly have a few of those "why is it so" moments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for clearing that up.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 06:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/78503#M16978</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-17T06:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Read Data Set through Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/477106#M122821</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro fun;
%do i=1 %to 2;

    data _null_;

        set lib.EMPLOYEE (firstobs=&amp;amp;i obs=&amp;amp;i);

        putlog " I want to print EMP_ID and EMP_NAME value for observation 1 and 2";
        
        
        

    run;

%end;
%mend fun;

%fun;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is good example ....But how do I print that observation ? For eg.&amp;nbsp; if dataset EMPLOYEE have EMP_ID and EMP_NAME columns then for that observation I want to print EMP_ID and EMP_NAME&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;</description>
      <pubDate>Wed, 11 Jul 2018 15:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-Data-Set-through-Do-Loop/m-p/477106#M122821</guid>
      <dc:creator>sam101</dc:creator>
      <dc:date>2018-07-11T15:37:04Z</dc:date>
    </item>
  </channel>
</rss>

