<?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 doing a insert into within a call execute in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534694#M146759</link>
    <description>Try removing the quotes and d.</description>
    <pubDate>Tue, 12 Feb 2019 02:50:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-12T02:50:44Z</dc:date>
    <item>
      <title>proc sql doing a insert into within a call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534691#M146758</link>
      <description>&lt;P&gt;Within a data setp I am using a "call execute" like the one below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute("proc sql;
insert into leaddata values("||subjid||","||mhterm||","||mhstdtc_dtr||","||mhstdtc_dtr||","||mhstdtc_dtr||","||sitemnemonic||","||mhstdtc2||"d,"||mhendtc2||"d);quit;");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Everything works fine except the last 2 variables mhstdtc2 and mhendtc2, these variables are num type with an informat and format of date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I receive a note that numeric variables are being converted to character on that line, How should the dates be inserted on the call execute statment. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 02:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534691#M146758</guid>
      <dc:creator>Madtim</dc:creator>
      <dc:date>2019-02-12T02:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql doing a insert into within a call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534694#M146759</link>
      <description>Try removing the quotes and d.</description>
      <pubDate>Tue, 12 Feb 2019 02:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534694#M146759</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-12T02:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql doing a insert into within a call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534695#M146760</link>
      <description>The quotes are not making the variable a character, as if I removed actually the sentence gets messy. Now, the d is to give date format when you insert dates, but removing it doesnt make a difference</description>
      <pubDate>Tue, 12 Feb 2019 02:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534695#M146760</guid>
      <dc:creator>Madtim</dc:creator>
      <dc:date>2019-02-12T02:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql doing a insert into within a call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534708#M146765</link>
      <description>&lt;P&gt;If you examine the end of the CALL EXECUTE logic, you are generating the wrong syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;","&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;mhstdtc2&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"d,"&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;mhendtc2&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"d);quit;"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming your date variables actually contain properly formatted date values, you are still generating something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;, 11Feb2019d, 12feb2019d); quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To give this the proper format, you need to generate date literals that look like this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;, '11Feb2019'd, '12Feb2019'd); quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This ought to do the trick:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;", '"&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;mhstdtc2&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'d, '"&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;mhendtc2&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'d);quit;"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Presumably the date variables contain the right number of characters, but if they give you any trouble you could apply the STRiP function to each:&amp;nbsp; || strip(mhstdtc2) ||&amp;nbsp; and&amp;nbsp; || strip(mhendtc2) ||&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;************************&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;On second thought, it gets a little more complicated.&amp;nbsp; If your variables are numeric, you would need:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;", '"&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||put(&lt;/SPAN&gt;mhstdtc2, date9.)&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'d, '"&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;||put(&lt;/SPAN&gt;mhendtc2, date9.)&lt;SPAN class="token operator"&gt;||&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'d);quit;"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 03:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534708#M146765</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-12T03:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql doing a insert into within a call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534760#M146797</link>
      <description>&lt;P&gt;Well, for an easy fix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;str=catx(',',subjid,mhterm,mhstdtc_dtr,mhstdtc_dtr,mhstdtc_dtr,&lt;BR /&gt;             sitemnemonic,put(mhstdtc2,best.),put(mhenddtc2,best.));&lt;BR /&gt;&lt;BR /&gt;call execute(cats("proc sql; insert into leaddata values(",str,"); quit;'));&lt;/PRE&gt;
&lt;P&gt;Note how I do the concatenation first, its easier to read.&amp;nbsp; You should just be able to put() the numbers into a string and have that inserted correctly, dates (and times/datetimes) are just numbers which are then "formatted" to look like dates.&lt;/P&gt;
&lt;P&gt;I would however question why you are doing this at all, it really can't be the best method to get what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 09:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534760#M146797</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-12T09:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql doing a insert into within a call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534793#M146802</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261369"&gt;@Madtim&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm very much with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;to take an approach where you first populate a SAS variable with the full command then then just use a call execute(&amp;lt;variable&amp;gt;);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking such an approach lets you "put" the variable into the log and you can see the full generated command and syntax check it. You can even copy/past it from the log to another program window and execute it. This makes debugging much easier - at least for me.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 12:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-doing-a-insert-into-within-a-call-execute/m-p/534793#M146802</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-12T12:36:00Z</dc:date>
    </item>
  </channel>
</rss>

