<?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: DO help please in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58261#M12657</link>
    <description>It would be helpful if you can post some data ,and explain what output you want after every iteration.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Thu, 28 Apr 2011 06:44:17 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-04-28T06:44:17Z</dc:date>
    <item>
      <title>DO help please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58259#M12655</link>
      <description>Good morning folks!&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped and need your help.&lt;BR /&gt;
&lt;BR /&gt;
Basic premise - we are playing with various scenarios in our data, and one &lt;BR /&gt;
of them is to adjust datasets based on critical values.&lt;BR /&gt;
&lt;BR /&gt;
The logic flow is to take the original dataset (which is divided into &lt;BR /&gt;
segment groupings), generate the statistic of interest by segment, and &lt;BR /&gt;
compare it to the chosen critical values for that segment.&lt;BR /&gt;
&lt;BR /&gt;
If the calculated statistic is smaller than the critical value for a &lt;BR /&gt;
segment, send the data out to a 'completed' dataset (ITSDONE).&lt;BR /&gt;
&lt;BR /&gt;
If the calculated statistic is larger than the critical value for a &lt;BR /&gt;
segment, delete the largest value in the dataset, and repeat until the critical value test is &lt;BR /&gt;
satisfied (NOTDONE).&lt;BR /&gt;
&lt;BR /&gt;
Unfortunately, I can't seem to figure out how to stop the do loop when &lt;BR /&gt;
the critical value test is satisfied (when NOTDONE is empty).&lt;BR /&gt;
&lt;BR /&gt;
The particular combination we are looking at right now requires 751 &lt;BR /&gt;
iterations for all segments to meet the test criteria.&lt;BR /&gt;
&lt;BR /&gt;
...until we change something (which we immediately will).&lt;BR /&gt;
&lt;BR /&gt;
I need to be able to do this without 'knowing' anything but the critical value and statistic.&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much for your help!&lt;BR /&gt;
&lt;BR /&gt;
Wendy T.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Dataset START already contains the critical value (K_CRIT), and is sorted &lt;BR /&gt;
by descending values of the variable ANGLE_K by SEGMENT.&lt;BR /&gt;
&lt;BR /&gt;
Dataset STACKER (to receive dataset ITSDONE) already exists, and contains &lt;BR /&gt;
one line with null values.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA LOOP ; SET START ; &lt;BR /&gt;
PROC MEANS NOPRINT N DATA=LOOP ;&lt;BR /&gt;
BY SEGMENT ;&lt;BR /&gt;
VAR ANGLE_K ;&lt;BR /&gt;
OUTPUT OUT=ORIG1 (DROP= _TYPE_ _FREQ_) N=ORIGINAL_N ; RUN ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
%MACRO CUTTOPVALUE ;&lt;BR /&gt;
&lt;BR /&gt;
%DO I=1 %TO 751 ;&lt;BR /&gt;
&lt;BR /&gt;
PROC MEANS NOPRINT DATA=LOOP ; &lt;BR /&gt;
BY SEGMENT ; &lt;BR /&gt;
VAR ANGLE_K  ;&lt;BR /&gt;
OUTPUT OUT=MEDIANS (DROP=_TYPE_) MEDIAN=MEDIAN ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL NOPRINT ;&lt;BR /&gt;
CREATE TABLE CHECKER&lt;BR /&gt;
AS SELECT LOOP.*, MEDIANS.MEDIAN, MEDIANS._FREQ_&lt;BR /&gt;
FROM LOOP, MEDIANS&lt;BR /&gt;
WHERE LOOP.SEGMENT=MEDIANS.SEGMENT ;&lt;BR /&gt;
QUIT ;&lt;BR /&gt;
&lt;BR /&gt;
DATA ITSDONE NOTDONE (DROP=MEDIAN _FREQ_) ; SET CHECKER ;&lt;BR /&gt;
IF MEDIAN LE K_CRIT THEN OUTPUT ITSDONE ;&lt;BR /&gt;
ELSE OUTPUT NOTDONE ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
DATA STACKER ; SET ITSDONE STACKER ; &lt;BR /&gt;
IF SEGMENT = '' THEN DELETE ; &lt;BR /&gt;
PROC SORT ; BY SEGMENT ; RUN ;&lt;BR /&gt;
&lt;BR /&gt;
DATA LOOP ; SET NOTDONE ;&lt;BR /&gt;
IF _N_ = 1 THEN DELETE ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
&lt;BR /&gt;
%END ;&lt;BR /&gt;
&lt;BR /&gt;
%MEND CUTTOPVALUE ;&lt;BR /&gt;
&lt;BR /&gt;
%CUTTOPVALUE ;&lt;BR /&gt;
&lt;BR /&gt;
DATA FINISHED ; MERGE STACKER ORIG1 ; BY SEGMENT ; RUN ;</description>
      <pubDate>Wed, 27 Apr 2011 16:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58259#M12655</guid>
      <dc:creator>WendyT</dc:creator>
      <dc:date>2011-04-27T16:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: DO help please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58260#M12656</link>
      <description>I'm not sure if I follow the logic in your program.&lt;BR /&gt;
I'm guessing that in you last data step within the macro loop know if you need to iterate again or not. &lt;BR /&gt;
If your don't need any more iterations, just call symput to a macro variable a certain value. This together with a %DO %WHILE or %UNTIL logic perhaps can do what you want?&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 28 Apr 2011 06:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58260#M12656</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2011-04-28T06:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: DO help please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58261#M12657</link>
      <description>It would be helpful if you can post some data ,and explain what output you want after every iteration.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 28 Apr 2011 06:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58261#M12657</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-28T06:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: DO help please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58262#M12658</link>
      <description>I finally figured it out! &lt;BR /&gt;
&lt;BR /&gt;
Sorry to not explain well.  Yes, my object was to get the number of observations remaining in dataset LOOP to see if I needed to iterate again. &lt;BR /&gt;
&lt;BR /&gt;
I was trying to use %symput to get the number of observations, but for some reason, I could not get it to work. (an example using call symput would be very welcome - I just now took a look at the documentation, and it's very unclear to me how to use it).&lt;BR /&gt;
&lt;BR /&gt;
So I went another way and matched the DO UNTIL with PROC SQL to the dictionary table.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help!&lt;BR /&gt;
&lt;BR /&gt;
Wendy T.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%MACROCUTTOPVALUE ;&lt;BR /&gt;
&lt;BR /&gt;
%DO %UNTIL (&amp;amp;NUMBOBS = 0) ;&lt;BR /&gt;
&lt;BR /&gt;
...as before ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL NOPRINT ;&lt;BR /&gt;
SELECT NOBS INTO :NUMBOBS FROM SASHELP.VTABLE&lt;BR /&gt;
WHERE LIBNAME='WORK' AND MEMNAME='LOOP'  ;&lt;BR /&gt;
QUIT; &lt;BR /&gt;
&lt;BR /&gt;
%END ;&lt;BR /&gt;
%MEND CUTTOPVAL ;</description>
      <pubDate>Tue, 03 May 2011 15:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58262#M12658</guid>
      <dc:creator>WendyT</dc:creator>
      <dc:date>2011-05-03T15:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: DO help please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58263#M12659</link>
      <description>Hi:&lt;BR /&gt;
  For some general macro overviews -- on overall macro processing and SYMPUT (among other topics), perhaps these papers will prove easier to go through:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/052-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/052-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings11/119-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/119-2011.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/wuss/2006/CodersCorner/COD-Gustafson.pdf" target="_blank"&gt;http://www.lexjansen.com/wuss/2006/CodersCorner/COD-Gustafson.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.nesug.org/proceedings/nesug98/code/p088.pdf" target="_blank"&gt;http://www.nesug.org/proceedings/nesug98/code/p088.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
 cynthia</description>
      <pubDate>Tue, 03 May 2011 22:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58263#M12659</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-05-03T22:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: DO help please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58264#M12660</link>
      <description>Instead of adding a separate PROC SQL step, you could just modify the last data step as follows. Code additions are documented in comments:&lt;BR /&gt;
&lt;BR /&gt;
DATA LOOP ; &lt;BR /&gt;
   /* Detect how many observations are in NOTDONE with nobs= */&lt;BR /&gt;
   SET NOTDONE nobs=NumObs; &lt;BR /&gt;
   /* Write the remining number of iterations to the NUMBOBS macro variable */&lt;BR /&gt;
   call symputx("NUMBOBS",NumObs-1);&lt;BR /&gt;
   IF _N_ = 1 THEN DELETE ;&lt;BR /&gt;
RUN ;</description>
      <pubDate>Thu, 05 May 2011 11:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-help-please/m-p/58264#M12660</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-05-05T11:53:13Z</dc:date>
    </item>
  </channel>
</rss>

