<?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: Repetitive calculations in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99023#M20866</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First off, you can do just about anything with SAS. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I took your code and wrapped the parts that run the proc dbf and proc variogram in a macro, since that code runs repetitively for each dbf in the folder. I added a data step after the ods output to reformat your ods output then appended it to a results data set that captures the stats for each run. Also, instead of using the list with the file names, I opted to read the file names directly from the folder by piping the dir command. Here's the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let mydir = c:\data\test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname mylib "&amp;amp;mydir";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA mylib.u107all;&lt;BR /&gt;length CODE $ 56.;&lt;BR /&gt;infile "&amp;amp;mydir\u107all.csv" dsd dlm=',' firstobs=2;&lt;BR /&gt;input CODE $ thevariable;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro analyze_dbf( fnm );&lt;BR /&gt;%let last4 = %substr( %scan( &amp;amp;fnm, 1, . ), 5, 4 );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename m "&amp;amp;mydir\&amp;amp;fnm";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC DBF db5=m out=mylib.m&amp;amp;last4; &lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt;PROC SQL;&lt;BR /&gt;create table mylib.ma&amp;amp;last4 as select&lt;BR /&gt;A.CODE, A.thevariable, B.CODE, B.POINT_X, B.POINT_Y&lt;BR /&gt;from mylib.u107all A, mylib.m&amp;amp;last4 B&lt;BR /&gt;where A.CODE = B.CODE;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods output "Autocorrelation Statistics" = mylib.moran&amp;amp;last4;&lt;BR /&gt;PROC VARIOGRAM data=mylib.ma&amp;amp;last4;&amp;nbsp; &lt;BR /&gt;compute novar autoc (weights=distance);&amp;nbsp; &lt;BR /&gt;coordinates xc=POINT_X yc=POINT_Y;&amp;nbsp; &lt;BR /&gt;var thevariable; &lt;BR /&gt;run; &lt;BR /&gt;quit;&lt;BR /&gt;ods output close;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data stats;&lt;BR /&gt;ma = &amp;amp;last4;&lt;BR /&gt;do until ( done );&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set mylib.moran&amp;amp;last4 end=done;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if coefficient =: 'Moran' then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; morano = observedvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; morane = expectedvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mz = z;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mp = pvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else if coefficient =: 'Geary' then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gearyo = observedvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gz = z;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp = pvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;end;&lt;BR /&gt;output;&lt;BR /&gt;keep ma morano--gp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc append base=mylib.results data=stats;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename x pipe "dir /b &amp;amp;mydir\*.dbf";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;infile x;&lt;BR /&gt;input fnm :$15.;&lt;BR /&gt;call execute ( cats( '%analyze_dbf(', strip(fnm), ');' ));&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 May 2012 21:02:03 GMT</pubDate>
    <dc:creator>FloydNevseta</dc:creator>
    <dc:date>2012-05-01T21:02:03Z</dc:date>
    <item>
      <title>Repetitive calculations in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99022#M20865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: times new roman,times; font-size: 12pt;"&gt;The &lt;STRONG&gt;dbflist.txt&lt;/STRONG&gt; contains all the 8-digit names of the dbf files in D:\myfolder.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: times new roman,times; font-size: 12pt;"&gt;For one dbf file (for example, &lt;STRONG&gt;00093282.dbf&lt;/STRONG&gt;), I run the following code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname mylib "D:\myfolder\";&lt;/P&gt;&lt;P&gt;DATA mylib.u107all;&lt;/P&gt;&lt;P&gt;length CODE $ 56.;&lt;/P&gt;&lt;P&gt;infile "D:\myfolder\u107all.csv" dsd dlm=',' firstobs=2;&lt;/P&gt;&lt;P&gt;input CODE $ thevariable;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename m3282 'D:\myfolder\00093282.dbf';&lt;/P&gt;&lt;P&gt;PROC DBF db5=m3282 out=mylib.m3282; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table mylib.ma3282 as select&lt;/P&gt;&lt;P&gt;A.CODE, A.thevariable, B.CODE, B.POINT_X, B.POINT_Y&lt;/P&gt;&lt;P&gt;from mylib.u107all A, mylib.m3282 B&lt;/P&gt;&lt;P&gt;where A.CODE = B.CODE;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods output "Autocorrelation Statistics" = mylib.moran3282;&lt;/P&gt;&lt;P&gt;PROC VARIOGRAM data=mylib.ma3282;&amp;nbsp; &lt;/P&gt;&lt;P&gt;compute novar autoc (weights=distance);&amp;nbsp; &lt;/P&gt;&lt;P&gt;coordinates xc=POINT_X yc=POINT_Y;&amp;nbsp; &lt;/P&gt;&lt;P&gt;var thevariable; run; quit;&lt;/P&gt;&lt;P&gt;ods output close;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: times new roman,times; font-size: 12pt;"&gt;Then, I have the mylib.ma3282 data set that contains some numbers of interst.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;VarName Assumption Coefficient Observed Expected Std Dev Z Pr &amp;gt; |Z|&lt;/P&gt;&lt;P&gt;thevariable Normality Moran's I &lt;STRONG&gt;-0.00242 -0.00252&lt;/STRONG&gt; 0.0000363 &lt;STRONG&gt;2.651 0.008 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;thevariable Normality Geary's c &lt;STRONG&gt;1.00023 1&lt;/STRONG&gt; 0.0004783 &lt;STRONG&gt;0.491 0.6237 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: times new roman,times; font-size: 12pt;"&gt;I want to collect the bold numbers in the mylib.ma3282 data set and create "result.txt" as follows:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ma morano morane mz mp gearyo gz gp&lt;/P&gt;&lt;P&gt;3282 -0.00242 -0.00252 2.651 0.008 1.00023 1 0.491 0.6237&lt;/P&gt;&lt;P&gt;5480 ... ... ... ... ... ... ... ... &lt;/P&gt;&lt;P&gt;5520 ... ... ... ... ... ... ... ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here, the field "ma" has the values that are the last 4 digits of the name of the dbf files. For 0009&lt;STRONG&gt;3282&lt;/STRONG&gt;.dbf, ma takes 3282.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I do that in SAS?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 04:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99022#M20865</guid>
      <dc:creator>tesu</dc:creator>
      <dc:date>2012-05-01T04:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitive calculations in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99023#M20866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First off, you can do just about anything with SAS. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I took your code and wrapped the parts that run the proc dbf and proc variogram in a macro, since that code runs repetitively for each dbf in the folder. I added a data step after the ods output to reformat your ods output then appended it to a results data set that captures the stats for each run. Also, instead of using the list with the file names, I opted to read the file names directly from the folder by piping the dir command. Here's the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let mydir = c:\data\test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname mylib "&amp;amp;mydir";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA mylib.u107all;&lt;BR /&gt;length CODE $ 56.;&lt;BR /&gt;infile "&amp;amp;mydir\u107all.csv" dsd dlm=',' firstobs=2;&lt;BR /&gt;input CODE $ thevariable;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro analyze_dbf( fnm );&lt;BR /&gt;%let last4 = %substr( %scan( &amp;amp;fnm, 1, . ), 5, 4 );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename m "&amp;amp;mydir\&amp;amp;fnm";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC DBF db5=m out=mylib.m&amp;amp;last4; &lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt;PROC SQL;&lt;BR /&gt;create table mylib.ma&amp;amp;last4 as select&lt;BR /&gt;A.CODE, A.thevariable, B.CODE, B.POINT_X, B.POINT_Y&lt;BR /&gt;from mylib.u107all A, mylib.m&amp;amp;last4 B&lt;BR /&gt;where A.CODE = B.CODE;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods output "Autocorrelation Statistics" = mylib.moran&amp;amp;last4;&lt;BR /&gt;PROC VARIOGRAM data=mylib.ma&amp;amp;last4;&amp;nbsp; &lt;BR /&gt;compute novar autoc (weights=distance);&amp;nbsp; &lt;BR /&gt;coordinates xc=POINT_X yc=POINT_Y;&amp;nbsp; &lt;BR /&gt;var thevariable; &lt;BR /&gt;run; &lt;BR /&gt;quit;&lt;BR /&gt;ods output close;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data stats;&lt;BR /&gt;ma = &amp;amp;last4;&lt;BR /&gt;do until ( done );&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set mylib.moran&amp;amp;last4 end=done;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if coefficient =: 'Moran' then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; morano = observedvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; morane = expectedvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mz = z;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mp = pvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else if coefficient =: 'Geary' then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gearyo = observedvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gz = z;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp = pvalue;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;end;&lt;BR /&gt;output;&lt;BR /&gt;keep ma morano--gp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc append base=mylib.results data=stats;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename x pipe "dir /b &amp;amp;mydir\*.dbf";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;infile x;&lt;BR /&gt;input fnm :$15.;&lt;BR /&gt;call execute ( cats( '%analyze_dbf(', strip(fnm), ');' ));&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 21:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99023#M20866</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-05-01T21:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Repetitive calculations in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99024#M20867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. I've learned a lot from you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 01:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repetitive-calculations-in-SAS/m-p/99024#M20867</guid>
      <dc:creator>tesu</dc:creator>
      <dc:date>2012-05-02T01:14:51Z</dc:date>
    </item>
  </channel>
</rss>

