<?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: PUT FUNCTION in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353787#M82609</link>
    <description>&lt;P&gt;You can just add the -L modifier onto the format to remove the leading spaces.&lt;/P&gt;
&lt;P&gt;If you know your numbers are intergers then no need to use the BEST format. &amp;nbsp;You should include a width in your format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char = put(intval,F17.-L);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 26 Apr 2017 16:47:00 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-04-26T16:47:00Z</dc:date>
    <item>
      <title>PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353721#M82579</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i remove leading or trailing blanks from variable VAR and at the same time convert to a charecter variable VAR1&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="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;var1=PUT(strip(var),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;best.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 14:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353721#M82579</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2017-04-26T14:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353722#M82580</link>
      <description>&lt;P&gt;Give us a clear example of a value of var that you want to convert to var1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question doesn't make sense because if you want to convert to a character value, then var must be numeric and numerics don't have trailing or leading blanks.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 14:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353722#M82580</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-26T14:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353730#M82583</link>
      <description>&lt;P&gt;THE VAR value is something like 0123456, 3456789 etc etc&lt;/P&gt;&lt;P&gt;This is giving me results .. Is this correct usage?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;VAR1=STRIP(put(VAR,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;best.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 14:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353730#M82583</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2017-04-26T14:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353739#M82586</link>
      <description>&lt;P&gt;This:&amp;nbsp;&lt;SPAN&gt;0123456&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Is not a number. &amp;nbsp;Hence I would assume from the that var is character, in which case you need to use string parsing functions or convert to numeric like:&lt;/P&gt;
&lt;PRE&gt;var=strip(put(input(var,best.),best.));
&lt;/PRE&gt;
&lt;P&gt;Which highlights again why&amp;nbsp;&lt;STRONG&gt;posting test data in the form of a datastep&lt;/STRONG&gt; is so vital to acurately answering a question.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353739#M82586</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-26T15:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353757#M82593</link>
      <description>&lt;P&gt;Thanks RW9.&lt;/P&gt;&lt;P&gt;Learnt two things here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my VAR is a number then this will suffice to convert to a charecter variable..&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;VAR1=STRIP(put(VAR,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;best.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;If my VAR is a&amp;nbsp;charecter then first convert to a numeric using INPUT?..&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Then again convert to a charecter variable using PUT function and then only can I use STRIP to remove any spaces?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;var=strip(put(input(var,best.),best.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;CANT I USE JUST THE BELOW TO CONVERT STRING TO NUMERIC:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;VAR1=STRIP(input(var,best.)&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353757#M82593</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2017-04-26T15:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353761#M82594</link>
      <description>&lt;P&gt;I am quite confused with what you are asking, post some examples in a datastep of what you mean as:&lt;/P&gt;
&lt;P&gt;If you have a character variable with spaces:&lt;BR /&gt;var=strip(var);&lt;/P&gt;
&lt;P&gt;Will remove all spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a numeric variable and you want a character variable, then you need to put it first into a new variable:&lt;/P&gt;
&lt;P&gt;newvar=strip(put(var,best.));&lt;/P&gt;
&lt;P&gt;The strip() is needed as it will pad out the number to fit the best format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric variables do not have "spaces" in them, so no problem..&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353761#M82594</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-26T15:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353766#M82596</link>
      <description>&lt;P&gt;STRIP is going to tell SAS that you want a character result as STRIP is a character function.&lt;/P&gt;
&lt;P&gt;To convert character to numeric use INPUT.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;VAR1=input(var,best.)&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;If that doesn't do what you want then you'll have to post example data that you have and what you actually want.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353766#M82596</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-26T15:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353769#M82599</link>
      <description>&lt;P&gt;The techniques are different, depending on whether VAR is character or numeric.&amp;nbsp; You will need to know that, to apply the proper code.&amp;nbsp; If you don't know, PROC CONTENTS will tell you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a character variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VAR1 = left(VAR);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There will still might be trailing blanks, but that is not avoidable.&amp;nbsp; If VAR has a length of 10, there is no way to change that with a function.&amp;nbsp; Even if you strip out leading and trailing blanks, SAS adds the trailing blanks back when it stores the variable using a length of 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For converting a numeric variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VAR1 = left(put(var, best.));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know something about the values to be found in your numeric variable, it might be better to assign a length to VAR1 before applying the PUT function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length VAR1 $ 10;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353769#M82599</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-26T15:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: PUT FUNCTION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353787#M82609</link>
      <description>&lt;P&gt;You can just add the -L modifier onto the format to remove the leading spaces.&lt;/P&gt;
&lt;P&gt;If you know your numbers are intergers then no need to use the BEST format. &amp;nbsp;You should include a width in your format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char = put(intval,F17.-L);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 16:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PUT-FUNCTION/m-p/353787#M82609</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-26T16:47:00Z</dc:date>
    </item>
  </channel>
</rss>

