<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<rss version="2.0">
<channel>
<title>THEN DO; - The five articles posted/edited most recently:</title>
<description>THEN DO; is the Newtyne SAS Hints and Tips Knowledgebase</description>
<link>http://www.newtyne.com/then_do</link>	<item>
		<title><![CDATA[Create a 'Progress/Processing' window while submitting remote code]]></title>
		<description><![CDATA[<p>Using the %window feature to create mini-applications sometimes require that SAS code is submitted remotely in an rsubmit block.</p><p>If the LOG window has been suppressed, it can be difficult for the user to know how whether anything is happening.</p><p>The following code can be used to generate a 'processing' window while the remote code is running, which then closes once processing is complete.</p><p>The code makes use of asynchronous processing allowing the rsubmit block to process in the background, while playing the 'animated' progress window in the foreground on the local machine.  It also makes use of the ability to pass a macro variable from the remote session to the local session, providing the trigger to stop the 'animation'.</p><p>The drawback to this process is that the packet passed from the remote processing will wait before updating the local macro variable if the local machine is busy. To allow time for the update, the local process uses the SLEEP function to add a millisecond delay to the animation.</p><pre>* Set option for Remote session to run asynchronously ;<br />* Set options for Remote Macro to synchronize on execution ;<br />* instead of at synchronization point ;<br /> <br />options noconnectwait sysrputsync ;<br /> <br />* Initialize macro variable on local session ;<br />%let rsub = 0 ;<br /> <br />* Connect to remote session ;<br />signon rmt sascmd="!sascmd" ;<br /> <br />rsubmit ;<br /> <br />* Do some processing - slowly! ;<br />  data temp ;<br />    do i = 1 to 100 ;<br />      x = ranuni(0) ;<br />   wait = sleep(5,.01) ;<br />      output ;<br />    end ;<br />  run ;<br /> <br />* Pass macro variable from remote session to local session ;<br />  %sysrput rsub = 1 ;<br /> <br />endrsubmit ;<br /> <br />* Define 'Please Wait' window ;<br /> <br />data _null_ ;<br />  window status<br />    group = static<br />    #8 @12 "Remote Submit Progress Window" persist = yes<br />    #12 @12 "Report running: Please wait" persist = yes<br />    <br />    group = progressbar<br />    #12 @(41 + progress) " » » » » » » » » » "<br />    ; <br /> <br /> display status.static noinput ;<br /> <br /> do until(input(symget('rsub'),1.)) ;<br />   do loop1 = 1 to 10 ;<br />     progress + 0.15 ;<br />     display status.progressbar noinput ;<br />* Need to pause the progress bar to allow the remote macro to update the local macro ;<br />     paused = sleep(1,.001) ;<br />   end ;<br />   progress = 0 ;<br /> end ;<br />run ;<br /> <br />signoff ;</pre>]]></description>
		<link>http://www.newtyne.com/then_do/index.php?action=artikel&amp;cat=7&amp;id=169&amp;artlang=en</link>
		<pubDate>Thu, 31 Jul 2008 14:55:08 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[Capture a macro variable in an interactive window and pass the value to a remote session.]]></title>
		<description><![CDATA[<p>The %WINDOW statement in SAS can be used to generate a bespoke window and capture user input as macro variables.  Unfortunately, it is not possible to invoke the %WINDOW statement from within a remote session RSUBMIT block.</p><p>An alternative is to capture the macro variable on the local session, then use the %SYSLPUT statement to transfer the macro variable from the local environment to the remote environment..</p><p>The following code gives a general example, capturing a date-string and passing to a remote session:</p><pre> 
%window passit
    #6  @12 "Enter a date (e.g. 18JUL2008)"
        @44 datevar 9 attr  = underline
                      color = green 
    #8  @12 "(If no date is specified today's date will be used.)" 
            color = gray
    #12 @12 "Make your selection, then press ENTER to continue" 
;

/* Check entered value - if nothing entered, or incorrect date       */
/* then return current date                                          */

%macro validdt ;
  %global datevar ;
  %let datevar= ; 
  %display passit blank ; 
  %if &amp;datevar = %then %let datevar = &amp;sysdate9 ;
  %else 
  %do ;
    options nonotes ;
    data _null_ ;
	  if input("&amp;datevar",date9.) = . then
	  do ;
	    _error_ = 0 ;
        call symput("datevar","&amp;sysdate9") ;
	  end ;
	run ;
	options notes ; 
  %end ;
%mend validdt ;

%validdt

options /*Specify site-specific options to establish remote session  */ ;

signon ;

/* Having established the remote connection, pass the Macro Variable */
/* created in the local session to the remote session                */

%syslput datevar = &amp;datevar ;

rsubmit ;

%put _user_ ;

/* Any other code on remote session here */

endrsubmit ;

signoff ;

</pre><p>The %SYSRPUT statement can be used to transfer a macro variable from the remote session to the local session.</p>]]></description>
		<link>http://www.newtyne.com/then_do/index.php?action=artikel&amp;cat=7&amp;id=168&amp;artlang=en</link>
		<pubDate>Fri, 18 Jul 2008 15:31:30 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[Changing Fonts and Font Sizes in LOG and OUTPUT windows]]></title>
		<description><![CDATA[<p>Normally when running SAS code in Interactive Windowing Mode no thought is given to the rendering of the LOG and OUTPUT - as long as it is readable.  For some people, however the default font and font size may not be suitable.  As always, however, SAS can accommodate.</p><p>To over-ride the default font and font-size in the LOG and OUTPUT windows, try issuing the following OPTIONS statement:</p><pre>OPTIONS font= "courier" 16;</pre><p>Which changes the font to Courier and the point-size to 16. It is also possible to add keywords for BOLD | NORMAL and REGULAR | ITALIC .</p><pre>OPTIONS font=&lt;font-name&gt; &lt;BOLD|NORMAL&gt; &lt;REGULAR|ITALIC&gt; &lt;font-size&gt; ;</pre><p /><p><strong>Top Tip:</strong> Stick with monospace fonts!<br />Proportional fonts can give some odd results, and cause a warning message in the log. (The developers at Newtyne Towers don't like warning messages in the log!)</p>]]></description>
		<link>http://www.newtyne.com/then_do/index.php?action=artikel&amp;cat=1&amp;id=167&amp;artlang=en</link>
		<pubDate>Thu, 17 Jul 2008 13:18:07 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[Re-create the Excel PMT function in SAS.]]></title>
		<description><![CDATA[<div align="justify">
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">In Excel, the PMT function returns 
the payment amount for a loan based on an interest rate and a constant payment 
schedule:</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">The syntax for the PMT function 
is:</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">    PMT( interest_rate, 
number_payments, PV, FV, Type )</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">interest_rate is the interest rate 
for the loan</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">number_payments is the number of 
payments for the loan</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">PV is the present value or 
principal of the loan</span></font></p></div>

<div align="justify">
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">FV is optional. It is the future 
value or the loan amount outstanding after all payments have been made. If this 
parameter is omitted, the PMT function assumes a FV value of 
0.</span></font></p></div>

<div align="justify">
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">Type is optional. It indicates 
when the payments are due. Type can be one of the following 
values:</span></font></p></div>
<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">    0  Payments are due at the end 
of the period. (default)<br />    1  Payments are due at the beginning of the 
period.</span></font></p></div>

<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">If the Type parameter is omitted, 
the PMT function assumes a Type value of 0.</span></font></p><div align="justify">

</div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">e.g. The monthly payment on a 
£5,000 loan at an annual rate of 7.5%. The loan is paid off in 2 years (ie: 2 x 
12). All payments are made at the beginning of the 
period.</span></font></p>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">        =PMT(7.5%/12, 2*12, 5000, 
0, 1)</span></font></p></div>

<div align="justify">
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">If using SAS, it might be 
necessary to establish the number of payments based on a start/end date.  Try 
looking at the INTCK function to count the number of interval periods between 
two dates e.g. number_payments = intck('month',today(),'01Mar2013'd) which will 
count the number of 'month' intervals between Feb 2008 and Mar 
2013.</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;"></span></font></p><p class="MsoNormal"></p><p align="justify" class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">If you don't want to 'build' this 
functionality from scratch, have a look at the MORT function in 
SAS:</span></font></p></div>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">MORT(a,p,r,n)  
</span></font></p></div>

<div>
<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size: 12pt;"></span></font><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">Arguments:</span></font></p></div>
<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">a <br />is numeric, the initial 
amount.</span></font></p></div>
<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">p <br />is numeric, the periodic 
payment.</span></font></p></div>
<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">r <br />is numeric, the periodic 
interest rate that is expressed as a 
fraction.</span></font></p></div>
<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">n <br />is an integer, the number of 
compounding periods. (Range: n ge 0)</span></font></p></div>

<div>
<div align="justify"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">The MORT function returns the 
missing argument in the list of four arguments from an amortization calculation 
with a fixed interest rate that is compounded each 
period.</span></font></div></div><div align="justify">

</div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">e.g. An amount of £50,000 is 
borrowed for 30 years at an annual interest rate of 10 percent compounded 
monthly. The monthly payment can be expressed 
as:</span></font></p>

<div>
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">   payment=mort(50000, . , 
.10/12,30*12);</span></font></p></div>

<div align="justify">
<p class="MsoNormal"><font size="2" face="Verdana"><span style="font-size: 10pt; font-family: Verdana;">The value returned is 438.79. The 
second argument has been set to missing, which indicates that the periodic 
payment is to be calculated. The 10 percent nominal annual rate has been 
converted to a monthly rate of 0.10/12. The rate is the fractional (not the 
percentage) interest rate per compounding period. The 30 years are converted 
into 360 months.</span></font></p></div>]]></description>
		<link>http://www.newtyne.com/then_do/index.php?action=artikel&amp;cat=14&amp;id=165&amp;artlang=en</link>
		<pubDate>Mon, 07 Apr 2008 14:23:19 GMT</pubDate>
	</item>
</channel>
</rss>