<?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: Macro Loop and Lag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111961#M23177</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to calculate all possible differences or to put it in other words compare all possible pairs of two values. As if for every ID I had a matrix (number_observations_for_id, 4) and I run through all rows and all columns and compare all possible pairs.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Apr 2013 09:53:55 GMT</pubDate>
    <dc:creator>snowflake</dc:creator>
    <dc:date>2013-04-18T09:53:55Z</dc:date>
    <item>
      <title>Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111958#M23174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Dear all&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my question:&lt;/P&gt;&lt;P&gt;I've the following dataset:&lt;/P&gt;&lt;P&gt;Id&amp;nbsp;&amp;nbsp; var1 var2 var3 var4 var5&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp; 66&amp;nbsp;&amp;nbsp; 88&amp;nbsp;&amp;nbsp; 888&amp;nbsp; 99&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 35&amp;nbsp;&amp;nbsp; 36&amp;nbsp;&amp;nbsp; 98&amp;nbsp;&amp;nbsp; 254 345&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 546&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51&amp;nbsp;&amp;nbsp; 564&amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 654&amp;nbsp; 87 54&amp;nbsp;&amp;nbsp;&amp;nbsp; 654&amp;nbsp; 651&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 546&amp;nbsp; 87&amp;nbsp; 861 651&amp;nbsp; 651&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 215&amp;nbsp; 55&amp;nbsp; 654&amp;nbsp; 896 514&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 654&amp;nbsp; 51&amp;nbsp; 678&amp;nbsp; 651&amp;nbsp; 215&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=&amp;gt; for every id I have several observations, but the number of observations per id varies.&lt;/P&gt;&lt;P&gt;Now I would like to calculate all pairwise differences within every id .&lt;/P&gt;&lt;P&gt;I found out that I could do this using proc transpose to put the dataset in a "wide" format and than use a loop over the transposed variables.&lt;/P&gt;&lt;P&gt;Before I found that solution I wondered if it is possible to do that only with loops and lag-function?&lt;/P&gt;&lt;P&gt;That idea brought me to the following problems:&lt;/P&gt;&lt;P&gt;1. Is it possible to have a macro call from within a data step with a data set value as an argument and execute that code immediately, not after the data step is executed. I know that you can use "call execute" to do a macro call with a data set value as argument, but the problem is that the generated code is only executed after the data step is finished.&lt;/P&gt;&lt;P&gt;2. Is there another solution to the above described problem without transposing the data?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 09:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111958#M23174</guid>
      <dc:creator>snowflake</dc:creator>
      <dc:date>2013-04-18T09:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111959#M23175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would be helpful if you could post what your output dataset should look like, based on the example data you have provided.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 09:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111959#M23175</guid>
      <dc:creator>Keith</dc:creator>
      <dc:date>2013-04-18T09:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111960#M23176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you please post the sample output you want...In your Question you want pairwise differences within each ID...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please define pairwise differences ???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 09:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111960#M23176</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-04-18T09:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111961#M23177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to calculate all possible differences or to put it in other words compare all possible pairs of two values. As if for every ID I had a matrix (number_observations_for_id, 4) and I run through all rows and all columns and compare all possible pairs.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 09:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111961#M23177</guid>
      <dc:creator>snowflake</dc:creator>
      <dc:date>2013-04-18T09:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111962#M23178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is not neat but should work:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Transpose the table so you only have just one value per row&lt;/LI&gt;&lt;LI&gt;Join the table with itself on id. Since there are multiple rows per id - a M-M join will occur.&lt;/LI&gt;&lt;LI&gt;Calculate the difference between the values from respective alias table&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;With this scenario you will also have a value minus itself calculated. To avoid that, ad a row no to the transposed table, and add a table_a.row_no &amp;lt;&amp;gt; table_b.row_no to the join criteria.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 10:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111962#M23178</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-04-18T10:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111963#M23179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try following macro...I am not sure about your requirement...like you said you whould like to compare all possible pairs of two values...It means that you want to have comparision of all the observations...If it is like that than try following code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;%macro test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 1 %to 2; /*I take stop value based on your unique ID values*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _diff_var_&amp;amp;i. = dif(var&amp;amp;i.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif;"&gt;%test&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;This will compare just observations for all the variables...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Again it will be good if you can post your output which you want to have...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;-Urvish&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 11:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111963#M23179</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-04-18T11:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111964#M23180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Urvish&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply. The problem with your solution ist that it only calculates the difference between the variable and with one lag of it.&lt;/P&gt;&lt;P&gt;What I would like is building all possible pairs within an id:&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;Id&amp;nbsp;&amp;nbsp; var1 var2 var3 var4 var5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp; 66&amp;nbsp;&amp;nbsp; 88&amp;nbsp;&amp;nbsp; 888&amp;nbsp; 99&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 35&amp;nbsp;&amp;nbsp; 36&amp;nbsp;&amp;nbsp; 98&amp;nbsp;&amp;nbsp; 254 345&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;1&amp;nbsp;&amp;nbsp; 546&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51&amp;nbsp;&amp;nbsp; 564&amp;nbsp; 22&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;&lt;/SPAN&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;2&amp;nbsp;&amp;nbsp; 654&amp;nbsp; 87&amp;nbsp;&amp;nbsp; 54&amp;nbsp;&amp;nbsp;&amp;nbsp; 654&amp;nbsp; 651&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;2&amp;nbsp;&amp;nbsp; 546&amp;nbsp; 87&amp;nbsp; 861&amp;nbsp;&amp;nbsp; 651&amp;nbsp; 651&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;2&amp;nbsp;&amp;nbsp; 215&amp;nbsp; 55&amp;nbsp; 654&amp;nbsp;&amp;nbsp; 896 514&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;2&amp;nbsp; 654&amp;nbsp; 51&amp;nbsp; 678&amp;nbsp;&amp;nbsp; 651&amp;nbsp; 215&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;Id dif1112&amp;nbsp; dif1113&amp;nbsp; dif1114&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dif1115&amp;nbsp;&amp;nbsp; dif1121&amp;nbsp; dif1122 ....&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;&lt;/SPAN&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;1 (45-66)&amp;nbsp;&amp;nbsp; (45-88)&amp;nbsp;&amp;nbsp; (45-888)&amp;nbsp;&amp;nbsp;&amp;nbsp; (45-888)&amp;nbsp; (45-35)&amp;nbsp;&amp;nbsp; (45-36)&amp;nbsp; ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;So for id=1 I have 15*14 differences for all possible combinations. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN lang="EN" style="font-family: 'Helvetica','sans-serif'; color: #575757; font-size: 10pt;"&gt;I know I can do it with proc transpose and loop over the variables. I just wanted to know if there is another way. Especially combing a loop and lag.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 12:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111964#M23180</guid>
      <dc:creator>snowflake</dc:creator>
      <dc:date>2013-04-18T12:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111965#M23181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is more easily solved (at pair level) with a "self join" in PROC SQL&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 13:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111965#M23181</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-04-18T13:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111966#M23182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an approach (although I definitely did not dot all the i's or cross all the t's).&amp;nbsp; It requires that you find out the maximum number of records for a single ID.&amp;nbsp; For illustration purposes, I'll use 4 as the max.&amp;nbsp; It also names the variables dif_001 - dif_190.&amp;nbsp; You could always spell out the names in the proper order (which is not 100% clear and might be the hardest part of the whole task).&amp;nbsp; Finally, it assumes that if you have taken the equivalent of dif1112, you do not need the same calculation in reverse order which would turn out to be dif1211.&amp;nbsp; After the long worded introduction, load a single dimensional array.&amp;nbsp; Then calculating all differences is fairly easy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array values {20} _temporary_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array diffs {190} dif_001 - dif_190;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array vars {5} var1-var5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; n_rows=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n_rows + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _n_=1 to 5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values{5*(n_rows-1) + _n_} = vars{_n_};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _n_=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do _i_=1 to 5*n_rows - 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _k_ = _i_ + 1 to 5*n_rows;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _n_ + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diffs{_n_} = values{_i_} - values{_k_};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All of this is untested code.&amp;nbsp; The naming difficulties might be easier if you were to use a two-dimensional array.&amp;nbsp; But the first step is to see if the approach makes sense to you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 16:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111966#M23182</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-04-18T16:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop and Lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111967#M23183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;tested, here is the pair-wise join in SQL&lt;/P&gt;&lt;P&gt;it creates 500 rows&lt;/P&gt;&lt;P&gt;data starting ;&lt;/P&gt;&lt;P&gt;input &lt;/P&gt;&lt;P&gt;Id&amp;nbsp;&amp;nbsp; var1 var2 var3 var4 var5;&lt;/P&gt;&lt;P&gt;list;cards;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp; 66&amp;nbsp;&amp;nbsp; 88&amp;nbsp;&amp;nbsp; 888&amp;nbsp; 99&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 35&amp;nbsp;&amp;nbsp; 36&amp;nbsp;&amp;nbsp; 98&amp;nbsp;&amp;nbsp; 254 345&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 546&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51&amp;nbsp;&amp;nbsp; 564&amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 654&amp;nbsp; 87 54&amp;nbsp;&amp;nbsp;&amp;nbsp; 654&amp;nbsp; 651&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 546&amp;nbsp; 87&amp;nbsp; 861 651&amp;nbsp; 651&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 215&amp;nbsp; 55&amp;nbsp; 654&amp;nbsp; 896 514&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 654&amp;nbsp; 51&amp;nbsp; 678&amp;nbsp; 651&amp;nbsp; 215&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data starting2 ;&lt;/P&gt;&lt;P&gt; set starting ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array vars (*) var: ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do varn = 1 to dim(vars) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var = vars(varn) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end ;&lt;/P&gt;&lt;P&gt; keep id varn var ; &lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;create table start2 as &lt;/P&gt;&lt;P&gt;select a.id, a.var as left, b.var as right, a.varn as leftN, b.varN as rightN &lt;/P&gt;&lt;P&gt;from starting2 as a&lt;/P&gt;&lt;P&gt;join starting2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; on a.id&amp;nbsp;&amp;nbsp; eq b.id&lt;/P&gt;&lt;P&gt; and a.varn ne b.varn &lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 23:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-and-Lag/m-p/111967#M23183</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-04-18T23:15:26Z</dc:date>
    </item>
  </channel>
</rss>

