<?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 how to right-justify a character matrix in sas/iml in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748133#M5486</link>
    <description>&lt;P&gt;i have a left-justified matrix of character labels that i want to right-justify for display.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there is an example in the SAS Help Center for the PUTC function that i have modified to teach myself:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;data test;&lt;BR /&gt;length a b $ 6 ;&lt;BR /&gt;&lt;BR /&gt;/* 123456 */&lt;BR /&gt;a = 'abc ' ;&lt;BR /&gt;b = put( a, $6. -R ) ;&lt;BR /&gt;put 'a=' a $6. ' b=' b $6. ;&lt;BR /&gt;&lt;BR /&gt;c = right( a ) ;&lt;BR /&gt;put 'a=' a $6. ' c=' c $6. ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;and it ret&lt;FONT size="4"&gt;urns the res&lt;/FONT&gt;ults correctly:&lt;/P&gt;&lt;DIV class="sasSource lia-indent-padding-left-30px"&gt;a=abc b= abc&lt;/DIV&gt;&lt;DIV class="sasSource lia-indent-padding-left-30px"&gt;a=abc c= abc&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;now, i want to use PROC IML to do a similar task:&lt;/DIV&gt;&lt;DIV class="sasSource lia-indent-padding-left-30px"&gt;proc iml ;&lt;BR /&gt;a={ 'a ', 'ab ', ' abc ', 'abcd' } ;&lt;BR /&gt;&lt;BR /&gt;a_put = put( a, '$6. -R' ) ; print a_put ;&lt;BR /&gt;&lt;BR /&gt;a_putc = putc( a, '$6. -R' ) ; print a_putc ;&lt;BR /&gt;&lt;BR /&gt;a_right =right( a ) ; print 'a=' a 'a_right=' a_right ;&lt;BR /&gt;quit ;&lt;FONT size="4"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT size="4"&gt;but the results are different:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rbettinger_0-1623766978912.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60410i4561EA856A2CBE84/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rbettinger_0-1623766978912.png" alt="rbettinger_0-1623766978912.png" /&gt;&lt;/span&gt;&lt;P&gt;note that put() is not defined:&lt;/P&gt;&lt;PRE class="sasLog"&gt;ERROR: Invocation of unresolved module PUT.&lt;/PRE&gt;&lt;P&gt;no right-justification has been performed. where is my error? how can i achieve my goal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA,&lt;/P&gt;&lt;P&gt;Ross Bettinger&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 15 Jun 2021 14:28:46 GMT</pubDate>
    <dc:creator>rbettinger</dc:creator>
    <dc:date>2021-06-15T14:28:46Z</dc:date>
    <item>
      <title>how to right-justify a character matrix in sas/iml</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748133#M5486</link>
      <description>&lt;P&gt;i have a left-justified matrix of character labels that i want to right-justify for display.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there is an example in the SAS Help Center for the PUTC function that i have modified to teach myself:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;data test;&lt;BR /&gt;length a b $ 6 ;&lt;BR /&gt;&lt;BR /&gt;/* 123456 */&lt;BR /&gt;a = 'abc ' ;&lt;BR /&gt;b = put( a, $6. -R ) ;&lt;BR /&gt;put 'a=' a $6. ' b=' b $6. ;&lt;BR /&gt;&lt;BR /&gt;c = right( a ) ;&lt;BR /&gt;put 'a=' a $6. ' c=' c $6. ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;and it ret&lt;FONT size="4"&gt;urns the res&lt;/FONT&gt;ults correctly:&lt;/P&gt;&lt;DIV class="sasSource lia-indent-padding-left-30px"&gt;a=abc b= abc&lt;/DIV&gt;&lt;DIV class="sasSource lia-indent-padding-left-30px"&gt;a=abc c= abc&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;now, i want to use PROC IML to do a similar task:&lt;/DIV&gt;&lt;DIV class="sasSource lia-indent-padding-left-30px"&gt;proc iml ;&lt;BR /&gt;a={ 'a ', 'ab ', ' abc ', 'abcd' } ;&lt;BR /&gt;&lt;BR /&gt;a_put = put( a, '$6. -R' ) ; print a_put ;&lt;BR /&gt;&lt;BR /&gt;a_putc = putc( a, '$6. -R' ) ; print a_putc ;&lt;BR /&gt;&lt;BR /&gt;a_right =right( a ) ; print 'a=' a 'a_right=' a_right ;&lt;BR /&gt;quit ;&lt;FONT size="4"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT size="4"&gt;but the results are different:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rbettinger_0-1623766978912.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60410i4561EA856A2CBE84/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rbettinger_0-1623766978912.png" alt="rbettinger_0-1623766978912.png" /&gt;&lt;/span&gt;&lt;P&gt;note that put() is not defined:&lt;/P&gt;&lt;PRE class="sasLog"&gt;ERROR: Invocation of unresolved module PUT.&lt;/PRE&gt;&lt;P&gt;no right-justification has been performed. where is my error? how can i achieve my goal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA,&lt;/P&gt;&lt;P&gt;Ross Bettinger&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 15 Jun 2021 14:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748133#M5486</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-06-15T14:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to right-justify a character matrix in sas/iml</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748148#M5487</link>
      <description>&lt;P&gt;When you use the HTML output destination, you can't use the PRINT statement (or PROC PRINT) to determine whether strings have multiple blanks because &lt;A href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace" target="_self"&gt;the HTML renderer "eats" extra blanks.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last line of your IML program is correct. You can use the RIGHT function &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_011/imlug/imlug_langref_sect550.htm" target="_self"&gt;(and most other Base SAS functions)&lt;/A&gt; in SAS/IML. As you point out, PUT is on the list of exceptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best way to verify that the spaces are really present is to translate them to some character (such as '*') that can be printed and counted. Here is how to use PROC PRINT for your example and how to use the PRINT statement in IML for your second example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
length a b $ 6 ;
/* 123456 */
a = 'abc ' ;
b = put( a, $6. -R ) ;
put 'a=' a $6. ' b=' b $6. ;
c = right( a ) ;
put 'a=' a $6. ' c=' c $6. ;
run;

/* note that the blanks do not appear when you display them in HTML */
proc print data=test;run;
/* however, you can replace blanks another character to see that they are there */
data test2;
set test;
array X[*] _CHARACTER_;
do i = 1 to dim(X);
   X[i] = translate(X[i], '*', ' ');
end;
drop i;
run;

proc iml ;
a={ 'a ', 'ab ', ' abc ', 'abcd' } ;
a_right =right( a ) ; /* right justify */

AA = a//a_right;      /* if you print AA, you won't see the blanks */
BB = translate(AA, '*', ' ');
print BB;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jun 2021 14:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748148#M5487</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-06-15T14:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to right-justify a character matrix in sas/iml</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748240#M5488</link>
      <description>&lt;P&gt;Thank you for helping me to understand the HTML renderer and for an excellent example demonstrating proper programming technique.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 00:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-right-justify-a-character-matrix-in-sas-iml/m-p/748240#M5488</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-06-16T00:27:33Z</dc:date>
    </item>
  </channel>
</rss>

