<?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: Truncation of macro variable with proc sql; select resolve(template) into :final_var in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501838#M583</link>
    <description>I'll inform my colleagues to use this consistently from now on ! &lt;BR /&gt;Thanks to all for the super fast replies !!!&lt;BR /&gt;</description>
    <pubDate>Fri, 05 Oct 2018 11:22:24 GMT</pubDate>
    <dc:creator>dirk_westmalle</dc:creator>
    <dc:date>2018-10-05T11:22:24Z</dc:date>
    <item>
      <title>Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501797#M574</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone explain why the first proc sql in the below example will truncate the resolved macro variable ?&lt;/P&gt;
&lt;P&gt;I was under the impression that macro variables can contain 65K and that resolving should only truncate if the final content exceeds the 65K border. As such it seemed reasonable to leave out a length statement in the proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second proc sql does not truncate the resolved variable, because I specified a length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifying a final length like in the second proc sql is not an option as we have more complex uses (multiple variables which are resolved multiple times) and trying to find the final length, would mean that we would have to actually recreate the resolve logic ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance to anyone that can help me to understand this issue.&lt;/P&gt;
&lt;P&gt;Dirk&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="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extraText=qwertzuiopasdfghjklöyxcvbnm;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; template &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$260.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; template=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'123456789012345678901234567890 &amp;amp;extraText 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*This one will truncate the resolved value */&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; resolve(template)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; :final_var separated by &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*This one will contain the complete resolved value*/&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; resolve(template) length=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;512&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; :final_var separated by &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 09:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501797#M574</guid>
      <dc:creator>dirk_westmalle</dc:creator>
      <dc:date>2018-10-05T09:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501806#M575</link>
      <description>&lt;P&gt;Have a peek in the test dataset, you will see the string is given a length of 260.&amp;nbsp; Now when the macro reference is resolved, and the text "&lt;SPAN&gt;qwertzuiopasdfghjklöyxcvbnm" added into that string, this pushes the length of the string past the 260 characters, so truncation happens.&amp;nbsp; By telling SAS the length, you have extended the number of characters the variable has, so no truncation is applied.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I really would however wonder, why you are making life so complicated for yourself.&amp;nbsp; The use of resolve, and macro's in text variables strongly indicates a bad process, much like more then one &amp;amp;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 10:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501806#M575</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-05T10:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501808#M576</link>
      <description>Does that mean that SAS will put the resolved value back in the table ? Sounds strange&lt;BR /&gt;&lt;BR /&gt;We use this technique to create complex json structures (with proc json ) dynamically.</description>
      <pubDate>Fri, 05 Oct 2018 10:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501808#M576</guid>
      <dc:creator>dirk_westmalle</dc:creator>
      <dc:date>2018-10-05T10:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501813#M577</link>
      <description>&lt;P&gt;Maxim 1: read the documentation.&lt;/P&gt;
&lt;P&gt;From &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1hffi0qkqzu78n1quvvl1szy9k6.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1hffi0qkqzu78n1quvvl1szy9k6.htm&amp;amp;locale=en&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2 id="n1esn96xoilr59n1swtr81jyud6z" class="xis-title" style="box-sizing: border-box; font-family: AvenirNext, Helvetica, Arial, sans-serif; font-weight: bold; line-height: 1.1; color: #333333; margin-top: 0.5em; margin-bottom: 10px; font-size: 1.125rem; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;Details&lt;/H2&gt;
&lt;DIV id="n1h7bzj9c4cwssn1b9phqrt40lln" class="xis-topicContent" style="box-sizing: border-box; color: #333333; font-family: AvenirNext, Helvetica, Arial, sans-serif; font-size: 14.08px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;
&lt;DIV id="n1rnumqqj8el9xn12l3yzz021vrx" class="xis-paragraph" style="box-sizing: border-box; margin-top: 1.4em;"&gt;If the RESOLVE function returns a value to a variable that has &lt;U&gt;&lt;EM&gt;not yet been assigned a length&lt;/EM&gt;&lt;/U&gt;, by default the variable is assigned a length of 200 bytes.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Emphasis by me)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The length of your macro variable is in fact 200, which can be verified by&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length = length("&amp;amp;final_var");
put length=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="xis-paragraph" style="box-sizing: border-box; margin-top: 1.4em;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 05 Oct 2018 10:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501813#M577</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-05T10:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501825#M579</link>
      <description>&lt;P&gt;Interesting, I have not used proc json so must get round to looking at it at some point.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 11:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501825#M579</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-05T11:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501826#M580</link>
      <description>Shame on me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;Should have read the manual. Is there a way to have this more dynamic</description>
      <pubDate>Fri, 05 Oct 2018 11:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501826#M580</guid>
      <dc:creator>dirk_westmalle</dc:creator>
      <dc:date>2018-10-05T11:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501833#M581</link>
      <description>We use assemble a proc json with a complex model in a temporary file. When the complete proc json is created, then we include that temporary file to generate the final json object, output it to the _webout and let a HTML page digest the data with JQuery code. Using proc json without the intermediate file does not allow complex data structures.</description>
      <pubDate>Fri, 05 Oct 2018 11:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501833#M581</guid>
      <dc:creator>dirk_westmalle</dc:creator>
      <dc:date>2018-10-05T11:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501836#M582</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/48238"&gt;@dirk_westmalle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Shame on me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;Should have read the manual. Is there a way to have this more dynamic&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In the proc sql, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/*This one will truncate the resolved value */
select resolve(template) length=32767
into :final_var separated by ''
from test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(use the maximum character variable length)&lt;/P&gt;
&lt;P&gt;The macro variable itself is automatically trimmed anyway, courtesy of the "separated by" clause (you could also use "trimmed"):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
test = "&amp;amp;final_var";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Variable test will have a length of 244. Without separated or trimmed, it would be 32767 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 11:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501836#M582</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-05T11:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Truncation of macro variable with proc sql; select resolve(template) into :final_var</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501838#M583</link>
      <description>I'll inform my colleagues to use this consistently from now on ! &lt;BR /&gt;Thanks to all for the super fast replies !!!&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Oct 2018 11:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Truncation-of-macro-variable-with-proc-sql-select-resolve/m-p/501838#M583</guid>
      <dc:creator>dirk_westmalle</dc:creator>
      <dc:date>2018-10-05T11:22:24Z</dc:date>
    </item>
  </channel>
</rss>

