<?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: Problems doing a loop in SAS Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625280#M184286</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312493"&gt;@Debugger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As loop I created the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro Loop;
%Do 1 %to &amp;amp;n;
PROC SQL;
   CREATE TABLE Tabelle&amp;amp;n AS 
   SELECT t1.Stichwort, 
          t1.Stichworttext, 
          t1.NM, 
          t1.Text, 
          t1.NAME, 
          t1.Tabellenname, 
          t2.&amp;amp;Joinfeld
      FROM &amp;amp;Tabelle
           FULL JOIN &amp;amp;tabelle t2 ON (t1.NM = t2.&amp;amp;Joinfeld)
      WHERE t1.NM NOT = '' AND t2.Joinfeld NOT = '';
QUIT; 
%End;
%Mend Loop;
%Loop;&lt;/PRE&gt;
&lt;P&gt;My Idea was to have variable "names" via which you can join the tables ("Joinfeld"), have distinct names for the tables ("tabelle") and iterations ("n").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;should say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to &amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but even that doesn't fix the problem as your loop variable doesn't appear inside the %DO loop, so there are many problems. Another problem is that your WHERE statement ought to say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE t1.NM NOT = '' AND t2.&amp;amp;Joinfeld NOT = '';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and still there may be more problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To further your own debugging, use the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the start of your program and run the program again. This will produce a LOG that ought to enable you to debug the problem better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To further our own attempts to help you, please use the above options statement, and show us the entire LOG for the macro — not just the error messages, but the entire log. Please copy the log as text and paste it into the window that appears when you click on the {i} icon, this makes the log format properly when we see it here in the SAS communities. DO NOT SKIP THE CLICKING ON THE {i} ICON STEP.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2020 14:38:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-02-17T14:38:00Z</dc:date>
    <item>
      <title>Problems doing a loop in SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625270#M184282</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;one problem is solved, the next arrives.&lt;/P&gt;&lt;P&gt;I am trying to automatize a comparison between one table (Table1) and its values and a lot of other tables, that should have the same respective values. There are probably missing values in the other tables and as Table1 is updated on a regular basis, this kind of macro would make my life much easier.&lt;/P&gt;&lt;P&gt;The comparison shall be executed in a way, so that the macro loops a comparison between Table1 and and the respective other table by joining them.&lt;/P&gt;&lt;P&gt;As a result I would like to have an output of a lot of different tables, that include the joins of the respective tables, so that any executor of the macro can easily spot missing values or matching values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In post XY I already posted the creation of the macro variables via SQL,&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/ERROR-22-322-ERROR-76-322-Macro-Variable-amp-n-generates-random/m-p/625264#M184276" target="_self"&gt;Former Post&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again here the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
select count(*) into :n
from work.Tabelle1;
%let n=&amp;amp;n;
Quit;

proc SQL;
Select distinct NAME into :name1 -
from work.Tabelle1;
Quit;
Proc SQL;
select distinct Tabellenname into :Joinfeld1 -
from work.Tabelle1;
Quit;&lt;/PRE&gt;&lt;P&gt;As loop I created the code:&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;PRE&gt;%Macro Loop;
%Do 1 %to &amp;amp;n;
PROC SQL;
   CREATE TABLE Tabelle&amp;amp;n AS 
   SELECT t1.Stichwort, 
          t1.Stichworttext, 
          t1.NM, 
          t1.Text, 
          t1.NAME, 
          t1.Tabellenname, 
          t2.&amp;amp;Joinfeld
      FROM &amp;amp;Tabelle
           FULL JOIN &amp;amp;tabelle t2 ON (t1.NM = t2.&amp;amp;Joinfeld)
      WHERE t1.NM NOT = '' AND t2.Joinfeld NOT = '';
QUIT; 
%End;
%Mend Loop;
%Loop;&lt;/PRE&gt;&lt;P&gt;My Idea was to have variable "names" via which you can join the tables ("Joinfeld"), have distinct names for the tables ("tabelle") and iterations ("n").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this seems logical or did i commit another easy error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before completing the loop. This Error message occurs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: An unexpected semicolon occurred in the %DO statement.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: A dummy macro will be compiled&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can u guys detect the probably very easy source of the mistake and realize whether my loop would work in the first place?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 14:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625270#M184282</guid>
      <dc:creator>Debugger</dc:creator>
      <dc:date>2020-02-17T14:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problems doing a loop in SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625280#M184286</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312493"&gt;@Debugger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As loop I created the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro Loop;
%Do 1 %to &amp;amp;n;
PROC SQL;
   CREATE TABLE Tabelle&amp;amp;n AS 
   SELECT t1.Stichwort, 
          t1.Stichworttext, 
          t1.NM, 
          t1.Text, 
          t1.NAME, 
          t1.Tabellenname, 
          t2.&amp;amp;Joinfeld
      FROM &amp;amp;Tabelle
           FULL JOIN &amp;amp;tabelle t2 ON (t1.NM = t2.&amp;amp;Joinfeld)
      WHERE t1.NM NOT = '' AND t2.Joinfeld NOT = '';
QUIT; 
%End;
%Mend Loop;
%Loop;&lt;/PRE&gt;
&lt;P&gt;My Idea was to have variable "names" via which you can join the tables ("Joinfeld"), have distinct names for the tables ("tabelle") and iterations ("n").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;should say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to &amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but even that doesn't fix the problem as your loop variable doesn't appear inside the %DO loop, so there are many problems. Another problem is that your WHERE statement ought to say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE t1.NM NOT = '' AND t2.&amp;amp;Joinfeld NOT = '';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and still there may be more problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To further your own debugging, use the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the start of your program and run the program again. This will produce a LOG that ought to enable you to debug the problem better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To further our own attempts to help you, please use the above options statement, and show us the entire LOG for the macro — not just the error messages, but the entire log. Please copy the log as text and paste it into the window that appears when you click on the {i} icon, this makes the log format properly when we see it here in the SAS communities. DO NOT SKIP THE CLICKING ON THE {i} ICON STEP.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 14:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625280#M184286</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-17T14:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problems doing a loop in SAS Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625390#M184311</link>
      <description>Wouldn't you design the macro such that any issues, such as missing are explicitly highlighted for the end user? &lt;BR /&gt;&lt;BR /&gt;Before starting with macros you should have working code that works for a single iteration, can you post that version and then an example of how you need to generalize it?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Feb 2020 18:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-doing-a-loop-in-SAS-Macro/m-p/625390#M184311</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-17T18:56:23Z</dc:date>
    </item>
  </channel>
</rss>

