<?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: PUTN error. What's the problem with the conversion to 6 characters? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937705#M368437</link>
    <description>&lt;P&gt;You don't need to use PUTN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your variable CLOSINGCYCLE is character, (length 6), you, can change the WHERE statement to just use the&amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;=:&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; &amp;nbsp;(equals then colon) comparison operator against the constant generated by the expression &lt;EM&gt;&lt;STRONG&gt;"&amp;amp;_CYCLE"&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; &amp;nbsp;The &lt;EM&gt;&lt;STRONG&gt;=:&lt;/STRONG&gt;&lt;/EM&gt; comparison takes the shorter character value (in _closingcycle) and compares it to an equal length substring of the longer character value (i.e. the first six characters of &amp;amp;_CYCLE).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where closingcycle&amp;nbsp;=:&amp;nbsp;&amp;nbsp;"&amp;amp;_CYCLE";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which produces the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where closingcycle =: "20180831";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2024 03:52:44 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-07-31T03:52:44Z</dc:date>
    <item>
      <title>PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937704#M368436</link>
      <description>&lt;P&gt;I have a question about the error message that i encountered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro variable named _CYCLE that has the string value 20180831 (8 characters).&lt;/P&gt;&lt;P&gt;In the macro test(), there is a dataset where its variable "CLOSINGCYCLE" is a character type and is currently storing value 201808 (just 6 characters).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hence, in the where clause, i first substr it to only taking the first 6 characters and then putn (convert it to character).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let _CYCLE = 20180831;

%macro test();
data SAP;
set OrigSAP;
WHERE CLOSINGCYCLE = putn(%substr(&amp;amp;_CYCLE.,1,6), 8.);         
%END;
run;

%mend;
%test;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, the error message that i am getting is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;SYMBOLGEN:  Macro variable _CYCLE resolves to 20180831
MPRINT(test):   WHERE CLOSINGCYCLE = putn(201808, 8.);
ERROR: Function PUTN requires a character expression as argument 2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What could be wrong here?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 02:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937704#M368436</guid>
      <dc:creator>StickyRoll</dc:creator>
      <dc:date>2024-07-31T02:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937705#M368437</link>
      <description>&lt;P&gt;You don't need to use PUTN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your variable CLOSINGCYCLE is character, (length 6), you, can change the WHERE statement to just use the&amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;=:&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; &amp;nbsp;(equals then colon) comparison operator against the constant generated by the expression &lt;EM&gt;&lt;STRONG&gt;"&amp;amp;_CYCLE"&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; &amp;nbsp;The &lt;EM&gt;&lt;STRONG&gt;=:&lt;/STRONG&gt;&lt;/EM&gt; comparison takes the shorter character value (in _closingcycle) and compares it to an equal length substring of the longer character value (i.e. the first six characters of &amp;amp;_CYCLE).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where closingcycle&amp;nbsp;=:&amp;nbsp;&amp;nbsp;"&amp;amp;_CYCLE";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which produces the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where closingcycle =: "20180831";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 03:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937705#M368437</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-31T03:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937728#M368445</link>
      <description>&lt;P&gt;The error message you are getting is simply that the second argument should be a character string with the format you want to use. Like this:&lt;/P&gt;
&lt;PRE&gt; 72         data _null_;
 73           a=putn(%substr(&amp;amp;_CYCLE.,1,6), '8.');
 74           put a $quote.;
 75         run;
 
 "  201808"&lt;/PRE&gt;
&lt;P&gt;This produces a right-aligned string of length 8. If that is what you want, I would suggest using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE CLOSINGCYCLE = "  %substr(&amp;amp;_CYCLE.,1,6)";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is a much simpler way to get the right-aligned string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 08:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937728#M368445</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2024-07-31T08:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937747#M368447</link>
      <description>&lt;P&gt;The error message tells you want is wrong:&lt;/P&gt;
&lt;PRE&gt;ERROR: Function PUTN requires a character expression as argument 2.&lt;/PRE&gt;
&lt;P&gt;So either make the second argument a character expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;putn(%substr(&amp;amp;_CYCLE.,1,6), '8.');   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just use the PUT() function instead since that want an actual FORMAT as the second argument, not a character expression.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(%substr(&amp;amp;_CYCLE.,1,6), 8.);   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2024 12:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937747#M368447</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-31T12:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937752#M368449</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p12zqzvwx4dv6kn1p9crijxswolk.htm" target="_blank" rel="noopener"&gt;PUTN Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will see that the second argument to the function has to be a&amp;nbsp;&lt;EM&gt;character expression&lt;/EM&gt;, not a format name which has to be interpreted by the DATA step compiler (as happens with the PUT and INPUT functions). So you either have to use the PUT function, or enclose the format specification in quotes. The former is recommended when a fixed format is used.&lt;/P&gt;
&lt;P&gt;PUTC, PUTN, INPUTC, INPUTN must be used within %SYSFUNC, as the data step compiler is not available there.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 13:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937752#M368449</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-07-31T13:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937756#M368450</link>
      <description>&lt;P&gt;If both variables are strings, why do you need the putn function?&lt;/P&gt;
&lt;P&gt;Try to drop it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;WHERE CLOSINGCYCLE = %substr(&amp;amp;_CYCLE.,1,6); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2024 14:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937756#M368450</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2024-07-31T14:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937758#M368451</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376676"&gt;@StickyRoll&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a question about the error message that i encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro variable named _CYCLE that has the string value 20180831 (8 characters).&lt;/P&gt;
&lt;P&gt;In the macro test(), there is a dataset where its variable "CLOSINGCYCLE" is a character type and is currently storing value 201808 (just 6 characters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence, in the where clause, i first substr it to only taking the first 6 characters and then putn (convert it to character).&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why would you need to convert a string back to a string???&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To specify a string constant in SAS code just enclose the text in quotes. Use double quotes so that the macro processor will "see" the %SUBSTR() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE CLOSINGCYCLE = "%substr(&amp;amp;_CYCLE.,1,6)" ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2024 14:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937758#M368451</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-31T14:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: PUTN error. What's the problem with the conversion to 6 characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937769#M368453</link>
      <description>&lt;P&gt;And you can avoid any macro coding altogether:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where closingcycle = "  " !! substr("&amp;amp;_CYCLE.",1,6);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which makes it clearer that you do want two leading blanks.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 15:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUTN-error-What-s-the-problem-with-the-conversion-to-6/m-p/937769#M368453</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-07-31T15:01:24Z</dc:date>
    </item>
  </channel>
</rss>

