<?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: Forcing alignment of numeric-turned-character variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437633#M109015</link>
    <description>&lt;P&gt;Doesn't align correctly when?&amp;nbsp; When you run a PROC PRINT?&amp;nbsp; Using which font?&amp;nbsp; When you run some other procedure?&amp;nbsp; When you export the data to Excel?&amp;nbsp; Do you have a log that shows how you got the non-aligned output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps all you are missing is a format statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;format put3 $char3.;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2018 15:31:27 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-15T15:31:27Z</dc:date>
    <item>
      <title>Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437553#M108972</link>
      <description>&lt;P&gt;I'm creating a table with counts + percentages in this format: &amp;nbsp;nnn (nnn.n)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want them to line up like this; numbers are made up, so no digs at my math skills ;-):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alignment.png" style="width: 99px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18609i4C67E091D554DB3C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alignment.png" alt="alignment.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The percentages in the parentheses are coming out fine, but I can't force the counts (before the parentheses) to align properly once I change them to character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="output.png" style="width: 354px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18610i99F0D0EB77A75E02/image-size/large?v=v2&amp;amp;px=999" role="button" title="output.png" alt="output.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C1 is the original numeric variable.&lt;/P&gt;&lt;P&gt;PUT3 = put(C1,3.);&lt;/P&gt;&lt;P&gt;STRIPPUT3 = strip(PUT3);&lt;/P&gt;&lt;P&gt;LEN = length(STRIPPUT3);&lt;/P&gt;&lt;P&gt;if&amp;nbsp;LEN = 1 then addblanks = " &amp;nbsp;"||compress(stripput3); **2 blanks added in front**;&lt;BR /&gt;if LEN = 2 then addblanks = " "||compress(stripput3); &amp;nbsp;**1 blank added in front**;&lt;BR /&gt;if LEN&amp;nbsp;= 3 then addblanks = compress(stripput3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even adding leading blanks doesn't align the character values the way the numeric values are. &amp;nbsp;Similar logic applied to the percentages works beautifully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is driving me nuts; what am I missing? &amp;nbsp;(Disclaimer: &amp;nbsp;I have not had my coffee yet.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VCM&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 12:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437553#M108972</guid>
      <dc:creator>VCM</dc:creator>
      <dc:date>2018-02-15T12:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437555#M108973</link>
      <description>&lt;P&gt;Perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;addblanks = '(' || put3 || ')';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or skip creating PUT3 entirely:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;addblanks = '(' || put(c1, 3.) || ')';&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437555#M108973</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T13:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437559#M108977</link>
      <description>These didn't work; the alignment of the characters in ADDBLANKS is still the same as above. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437559#M108977</guid>
      <dc:creator>VCM</dc:creator>
      <dc:date>2018-02-15T13:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437568#M108980</link>
      <description>&lt;P&gt;you can either:&lt;/P&gt;&lt;P&gt;1. Use a leading zeros&amp;nbsp;format or leading spaces (replaces the 0 with space):&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;CODE class=" language-sas"&gt;data test;
/*create two value*/
c1=104;
c2=2;
/*add leading zeros*/
z1=c1;
z2=c2;
put1=put(c1,z8.);
put2=put(c2,z8.);
/*add leadin spaces*/
string1=tranwrd(put(c1,z8.),'0',' ');
string2=tranwrd(put(c2,z8.),'0',' ');
format  z1 z8.  z2 z8. ;
put _ALL_;
run;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Log&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;c1=104 c2=2 z1=00000104 z2=00000002 put1=00000104 put2=00000002 string1=1 4 string2=2 _ERROR_=0 _N_=1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="z.JPG" style="width: 683px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18614i9E49968CEFFD1858/image-dimensions/683x33?v=v2" width="683" height="33" role="button" title="z.JPG" alt="z.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you want this field to be character with leading spaces instead of 0&lt;/P&gt;&lt;P&gt;2. use the alignment / justify option in proc print; please refer to this &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Proc-print-Center-justify-column-heading/td-p/106814 " target="_blank"&gt;post&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437568#M108980</guid>
      <dc:creator>Mo_NHS</dc:creator>
      <dc:date>2018-02-15T13:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437571#M108982</link>
      <description>&lt;P&gt;Please clear us on&lt;BR /&gt;1. What your data should look like.&lt;BR /&gt;2. What your data looks like now.&lt;BR /&gt;3, Source data&lt;BR /&gt;4. Codes you have written.&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437571#M108982</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-15T13:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437592#M108989</link>
      <description>&lt;P&gt;Would not the right function do what you want, assuming you always have 1 decimal place:&lt;/P&gt;
&lt;PRE&gt;data want;
  length b $10.;
  a=0.1;
  b=cat("(",right(put(a,5.1)),")");
  output;
  a=123.1;
  b=cat("(",right(put(a,5.1)),")");
  output;
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 14:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437592#M108989</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T14:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437598#M108991</link>
      <description>&lt;P&gt;It worked for me (see sample program below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's not working for you, you might have to show your log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;data &lt;/FONT&gt;&lt;FONT face="Lucida Console" size="2"&gt;test&lt;/FONT&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input c;&lt;/P&gt;
&lt;P&gt;put3 = put(c, 3.);&lt;/P&gt;
&lt;P&gt;addblanks = '(' || put3 || ')';&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;82&lt;/P&gt;
&lt;P&gt;104&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;proc print; run;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 14:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437598#M108991</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T14:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437623#M109008</link>
      <description>&lt;P&gt;I'm not trying to align the numbers within the parentheses--those are coming out fine. &amp;nbsp;I'm trying to align the numbers in front of the parentheses. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that if you &lt;STRONG&gt;put(number,format.)&lt;/STRONG&gt; to create a character variable, it would automatically left-align it (then all I would have to do is add leading blanks where needed), but that doesn't seem to be the case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437623#M109008</guid>
      <dc:creator>VCM</dc:creator>
      <dc:date>2018-02-15T15:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437625#M109010</link>
      <description>Thanks, but I'm not worried about the numbers in parentheses; I need to align the 3-digit/character number in front of the parentheses.</description>
      <pubDate>Thu, 15 Feb 2018 15:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437625#M109010</guid>
      <dc:creator>VCM</dc:creator>
      <dc:date>2018-02-15T15:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437627#M109011</link>
      <description>&lt;P&gt;No, the leading blanks are not removed.&amp;nbsp; This should be fine:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;put3 = put(c1, 3.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PUT3 does contain leading blanks.&amp;nbsp; If you don't see them, it would be related to how you are viewing (or printing) PUT3.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437627#M109011</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T15:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437630#M109013</link>
      <description>That's why I added&lt;BR /&gt;STRIPPUT3 = strip(PUT3);&lt;BR /&gt;LEN = length(STRIPPUT3);&lt;BR /&gt;&lt;BR /&gt;You can see in the original post that STRIPPUT3 does left-align and the lengths are correct. But when I add 2 leading blanks to "3" and one leading blank to "82", you can see it still doesn't align correctly.</description>
      <pubDate>Thu, 15 Feb 2018 15:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437630#M109013</guid>
      <dc:creator>VCM</dc:creator>
      <dc:date>2018-02-15T15:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437633#M109015</link>
      <description>&lt;P&gt;Doesn't align correctly when?&amp;nbsp; When you run a PROC PRINT?&amp;nbsp; Using which font?&amp;nbsp; When you run some other procedure?&amp;nbsp; When you export the data to Excel?&amp;nbsp; Do you have a log that shows how you got the non-aligned output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps all you are missing is a format statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;format put3 $char3.;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437633#M109015</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T15:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437639#M109016</link>
      <description>&lt;P&gt;Since the only thing that should worry about things like decimal alignment&amp;nbsp;are people then the changing data values is NOT the way to approach this. In general the output report generators like Proc Print, Tabulate or Report will right align values which means decimal points won't align but any integer values will.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS supplies&amp;nbsp;several &amp;nbsp;formats that will align decimals on output such as BESTDw.p or Dw.p. Use one of these in printed or ODS output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And many times your "failure" to force alignment of a character value will occur because of proportional fonts and the way they treat multiple spaces and the width of characters displaye&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 22:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437639#M109016</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-15T22:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing alignment of numeric-turned-character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437645#M109018</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
/*create two value*/
c1=104;
c2=2;
/*use right alignment*/
s1=right(put(c1,8.))||" (99.00)";
s2=right(put(c2,8.))||" (99.00)";
output;
/*create another row*/
c1=2;
c2=104;
s1=right(put(c1,8.))||" (99.00)";
s2=right(put(c2,8.))||" (99.00)";
output;
put _ALL_;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="z.JPG" style="width: 603px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18619i485FD30FD2E6EA9A/image-dimensions/603x124?v=v2" width="603" height="124" role="button" title="z.JPG" alt="z.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forcing-alignment-of-numeric-turned-character-variables/m-p/437645#M109018</guid>
      <dc:creator>Mo_NHS</dc:creator>
      <dc:date>2018-02-15T15:45:12Z</dc:date>
    </item>
  </channel>
</rss>

