<?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: PROC SQL Insert DO LOOP with a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459763#M116808</link>
    <description>&lt;P&gt;Or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro StartTable (whichsite);
 PROC SQL;
 %do k = 0 %to 11;
INSERT INTO work.Temp
	Set site= &amp;amp;whichsite.
	,DurationCat = put(1+( &amp;amp;k.*.25),5.2)
	,DurationCount=0
   ;    /*; to end each insert statement*/
%END
	quit;
%mend StartTable;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 May 2018 17:31:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-05-03T17:31:10Z</dc:date>
    <item>
      <title>PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459742#M116798</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am trying to prepopulate a table with some values to make sure all combinations are accounted for in the final data set .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested a simple PROC SQL insert step:&lt;/P&gt;&lt;PRE&gt;PROC SQL;
 
INSERT INTO work.Temp
	Set site= 'WBK'
	,DurationCat = put(1+( 1*.25),5.2)
	,DurationCount=0
	;quit;&lt;/PRE&gt;&lt;P&gt;to make sure I had the right syntax for the insert, and it worked as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now what I want is to pass the Site name in through a Macro, and then do a loop where the 1*.25 is actually {0*.25,1*.25... ...10*.25,11*.25}&lt;/P&gt;&lt;P&gt;this way I get an entry for each site with a duration category of 1 to 3.75&amp;nbsp;&amp;nbsp; moving by 0.25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I modify the code to a macro :&lt;/P&gt;&lt;PRE&gt;%Macro StartTable (whichsite);
 PROC SQL;
 %do k = 0 %to 11;
INSERT INTO work.Temp
	Set site= &amp;amp;whichsite.
	,DurationCat = put(1+( &amp;amp;k.*.25),5.2)
	,DurationCount=0
%END
	;quit;
%mend StartTable;&lt;/PRE&gt;&lt;P&gt;which I call with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%StartTable(whichsite='WBK');
%StartTable(whichsite='WCK');
%StartTable(whichsite='WDK');&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I am getting this error:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !!, *, **, +, ',', -, /, SET, ||.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am sure I am doing something dumb and missing a simple syntax error, but for the life of me I can't figure it out. Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 16:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459742#M116798</guid>
      <dc:creator>Puertorekinsam</dc:creator>
      <dc:date>2018-05-03T16:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459743#M116799</link>
      <description>&lt;P&gt;A couple of issues. If you show us the SASLOG, we might better be able to determine where/what the error is. Just showing us the error message doesn't help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, if you are having problems with macros, and you have already gotten the code to work without macros, then you need to 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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before you run your code, this will cause SAS to show you the actual code used&amp;nbsp;by resolving the macro, and this actual code used will appear in the SASLOG. At that point, you ought to be able to pick out the error yourself.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 16:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459743#M116799</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-03T16:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459747#M116800</link>
      <description>&lt;P&gt;see if this works?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro StartTable (whichsite);
 PROC SQL;
 %do k = 0 %to 11;
INSERT INTO work.Temp
	Set site= "&amp;amp;whichsite."
	,DurationCat = put(1+( &amp;amp;k.*.25),5.2)
	,DurationCount=0
%END
	;quit;
%mend StartTable;

%StartTable(whichsite=WBK);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 May 2018 17:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459747#M116800</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-03T17:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459754#M116803</link>
      <description>&lt;P&gt;Is somebody forcing you to use SQL?&amp;nbsp; This is a really easy task for a DATA step, along the lines of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;DurationCount=0;&lt;/P&gt;
&lt;P&gt;do Site='WBK', 'WCK', 'WDK';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do k=1 to 11;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DurationCat = put(1 + (k * 0.25), 5.2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;drop k;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 17:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459754#M116803</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-03T17:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459760#M116806</link>
      <description>&lt;P&gt;No, it's more of a "the devil you know" type situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I bounce around from environment to environment based on my needs are (SAS... [R]...Python... Business Objects), I usually do a lot with SQL so I can transfer from one to the other.&lt;/P&gt;&lt;P&gt;Also, I have a lot more sites then the three listed, sometimes they are fed by a user prompt, so I am not limited to just those three, I just gave those as an example because I have seen comments on these boards before of " you're not calling the Macro". Since I knew that wasn't the issue, I wanted to make sure I accounted for it.&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;P&gt;I did solve the issue thanks to PaigeMiller's comment about &lt;STRONG&gt;options mprint;&lt;/STRONG&gt; I was missing a semicolon (and I put the %DO loop back around the SQL and not in the code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; %macro StartTable(whichsite);
%do k = 0 %to 11;
PROC SQL;
INSERT INTO work.Temp
	Set site= &amp;amp;whichsite
	,DurationCat = put(1+( &amp;amp;k*.25),5.2)
	,DurationCount=0
;quit;
%END;

%mend StartTable;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 May 2018 17:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459760#M116806</guid>
      <dc:creator>Puertorekinsam</dc:creator>
      <dc:date>2018-05-03T17:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459762#M116807</link>
      <description>&lt;P&gt;Thanks! I came to the same solution once I turned on the mprint options... The things I don't know since I have no formal training in this stuff...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone!&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 17:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459762#M116807</guid>
      <dc:creator>Puertorekinsam</dc:creator>
      <dc:date>2018-05-03T17:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Insert DO LOOP with a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459763#M116808</link>
      <description>&lt;P&gt;Or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro StartTable (whichsite);
 PROC SQL;
 %do k = 0 %to 11;
INSERT INTO work.Temp
	Set site= &amp;amp;whichsite.
	,DurationCat = put(1+( &amp;amp;k.*.25),5.2)
	,DurationCount=0
   ;    /*; to end each insert statement*/
%END
	quit;
%mend StartTable;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 May 2018 17:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Insert-DO-LOOP-with-a-Macro/m-p/459763#M116808</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-03T17:31:10Z</dc:date>
    </item>
  </channel>
</rss>

