<?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: converting numeric to character using compress? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698205#M213504</link>
    <description>&lt;P&gt;Here's the documentation on &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p12zqzvwx4dv6kn1p9crijxswolk.htm&amp;amp;locale=en" target="_self"&gt;PUTN function&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;There's links to the PUT function too, and some examples&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Nov 2020 19:32:23 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2020-11-11T19:32:23Z</dc:date>
    <item>
      <title>converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698196#M213499</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to convert a numeric variables (all the numbers are whole numbers, no decimals) to character because I need to insert some character symbols and I seem to be able to do the conversion using compress. i.e. new=compress(old). This seems to work. Is this bad practice? Can using compress for this num to char conversion introduce some sort of errors that I am not aware of?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 17:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698196#M213499</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2020-11-11T17:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698199#M213501</link>
      <description>&lt;P&gt;COMPRESS is a character function, so you should not use it on numbers (unnecessary NOTE in the log).&lt;/P&gt;
&lt;P&gt;Use a PUT function with a proper format and the left-alignment modifier.&lt;/P&gt;
&lt;P&gt;If you need to insert characters at fixed positions in numbers with consistent numbers of digits, create a picure format.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 18:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698199#M213501</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-11T18:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698200#M213502</link>
      <description>&lt;P&gt;The COMPRESS() function is for removing characters from a string.&amp;nbsp; So the COMPRESS() function works on character arguments, not on numbers. (what would it even mean on a number?)&lt;/P&gt;
&lt;P&gt;But SAS will automatically convert your number into a character, which will generate notes to the low.&lt;/P&gt;
&lt;P&gt;To avoid the notes use the PUT() function to convert the number into a character string.&amp;nbsp; That way you can use the proper format.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(old,17.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do not give COMPRESS the optional second argument it will remove the spaces from the string.&amp;nbsp; The only spaces PUT will generate with the format will be leading spaces.&amp;nbsp; You can remove the leading spaces using the LEFT() function (you can ignore any trailing spaces as SAS stores character variables as fixed length values padded with spaces).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new=left(put(old,17.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use the -L modifier on the format to have PUT left align the string for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new=put(old,17.-L);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Nov 2020 18:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698200#M213502</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-11T18:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698201#M213503</link>
      <description>I’m not sure what the proper format is. The length is 8, can I use 8. as the format?&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Nov 2020 19:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698201#M213503</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2020-11-11T19:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698205#M213504</link>
      <description>&lt;P&gt;Here's the documentation on &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p12zqzvwx4dv6kn1p9crijxswolk.htm&amp;amp;locale=en" target="_self"&gt;PUTN function&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;There's links to the PUT function too, and some examples&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 19:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698205#M213504</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-11-11T19:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698208#M213505</link>
      <description>&lt;P&gt;The LENGTH of a variable in SAS is how many bytes it takes to store the variable in the dataset. Since numbers are always stored as floating point the length of 8 is the default (you can elect to use fewer bytes to store the numbers but that just loses precision on the number being stored. )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The width of the format to use when converting the number to a character string depends on the values that the variable could hold.&amp;nbsp; If the values are integers then the largest integer that can be represent exactly contiguously is&amp;nbsp;9,007,199,254,740,992 (at least on systems using IEEE floating point numbers) which would need 16 characters.&amp;nbsp; But you might also have a negative value.&amp;nbsp; So by using the format of 17. you can represent any integer you might have stored (or at least any that you could consistently store and retrieve).&lt;/P&gt;
&lt;PRE&gt;3879  data _null_;
3880    x=constant('exactint');
3881    put x comma24.;
3882  run;

   9,007,199,254,740,992&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 19:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698208#M213505</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-11T19:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: converting numeric to character using compress?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698212#M213506</link>
      <description>&lt;P&gt;When one wants to insert characters into numbers, this usually happens at fixed positions within a fixed number of digits.&lt;/P&gt;
&lt;P&gt;Please give us some examples of the numbers you have and how you want them to appear in the end.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 19:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-numeric-to-character-using-compress/m-p/698212#M213506</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-11T19:50:46Z</dc:date>
    </item>
  </channel>
</rss>

