<?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([var],[format]) not working ?? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296978#M62310</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the following code, you see no errors because you have defined the variable &lt;STRONG&gt;count2 &lt;/STRONG&gt;with length &lt;STRONG&gt;5&lt;/STRONG&gt; while in the function you have the formula: put(count,8.). Therefore the value is truncated. Change the length to 8 and it will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
      length count2 $5;
      set junk.Part1a_count;
      if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";
      else count2=put(count,8.);
      where zipcode ne "";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While for the last submitted code you get the warning because you use &lt;STRONG&gt;character format &lt;/STRONG&gt;to an already numeric defined variable within the put formula. Change the formula to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(put(count,5.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
      length count2 $5;
      set junk.Part1a_count;
      if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";
      else count2=left(put(count,$5.));
      where zipcode ne "";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Sep 2016 14:43:43 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2016-09-07T14:43:43Z</dc:date>
    <item>
      <title>put([var],[format]) not working ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296974#M62308</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran a frequency and now i want to create a second table off the first table and make the numeric count into a character count so that i can suppress low turnout values with an asterisk.&amp;nbsp; Originally, i tried input(), since i was going from numeric to character.&amp;nbsp; In end, i tried all 4 options.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run this one, and I get the "numeric values converted to character" in the log, and the count2 values are now "." for everything that should have an actual value:&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length count2 $5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set junk.Part1a_count;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else count2=input(count,8.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where zipcode ne "";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run this one, and I get the "numeric values converted to character" in the log, but no values in count2 where there should be values.&amp;nbsp; Just blanks.&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length count2 $5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set junk.Part1a_count;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else count2=left(input(count,$5.));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where zipcode ne "";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run this, get no errors, but no values in count2 where there should be values.&amp;nbsp; Just blanks:&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length count2 $5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set junk.Part1a_count;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else count2=put(count,8.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where zipcode ne "";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i run this, I get a warning in the log that count has already been defined as numeric, but it works.&lt;BR /&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length count2 $5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set junk.Part1a_count;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else count2=left(put(count,$5.));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where zipcode ne "";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the code to make it work, but without the warning message?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 14:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296974#M62308</guid>
      <dc:creator>MeganE</dc:creator>
      <dc:date>2016-09-07T14:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: put([var],[format]) not working ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296977#M62309</link>
      <description>&lt;P&gt;Going back to your very first DATA step, this statement is incorrect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else count2=input(count, 8.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The way to convert COUNT to character is to use the PUT function.&amp;nbsp; Since COUNT2 is defined as having a length of 5, try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else count2=put(count,5.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That should get you most of the way there (possibly all the way there).&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 14:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296977#M62309</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-07T14:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: put([var],[format]) not working ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296978#M62310</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the following code, you see no errors because you have defined the variable &lt;STRONG&gt;count2 &lt;/STRONG&gt;with length &lt;STRONG&gt;5&lt;/STRONG&gt; while in the function you have the formula: put(count,8.). Therefore the value is truncated. Change the length to 8 and it will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
      length count2 $5;
      set junk.Part1a_count;
      if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";
      else count2=put(count,8.);
      where zipcode ne "";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While for the last submitted code you get the warning because you use &lt;STRONG&gt;character format &lt;/STRONG&gt;to an already numeric defined variable within the put formula. Change the formula to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(put(count,5.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
      length count2 $5;
      set junk.Part1a_count;
      if 1 &amp;lt;= count &amp;lt;= 10 then count2="*";
      else count2=left(put(count,$5.));
      where zipcode ne "";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2016 14:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296978#M62310</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-09-07T14:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: put([var],[format]) not working ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296979#M62311</link>
      <description>&lt;P&gt;It worked.&amp;nbsp; Though, without the error, that's the fourth one i tried!&amp;nbsp; Except i had a $ in there.&amp;nbsp; But count2 is character.&amp;nbsp; Shouldn't the 5 be a $5?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 14:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296979#M62311</guid>
      <dc:creator>MeganE</dc:creator>
      <dc:date>2016-09-07T14:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: put([var],[format]) not working ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296981#M62312</link>
      <description>&lt;P&gt;No dollar sign needed ... the PUT function always returns a character string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding a $ or not depends on whether the incoming variable (COUNT in this case) is character or numeric.&amp;nbsp; Since it is numeric, don't add the dollar sign.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 14:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296981#M62312</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-07T14:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: put([var],[format]) not working ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296988#M62315</link>
      <description>&lt;P&gt;If you have multiple variables that would have the same "low count" to suppress you may be better off using a custom format.&lt;/P&gt;
&lt;P&gt;Then you just print the data using that format. The example below will show any value of 10 or less as * and anything else formats as best10. You could specify any other format such as F10.2 or comma8. that you might want the varaibles displayed with.&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;proc format library=work;
   Value belowten
   low - 10 = "*"
   other = [best10.];
run;

data example;
   do x= 1 to 20;
   output;
   end;
run;

proc print data=example;
   var x;
   format x belowten.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2016 15:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-var-format-not-working/m-p/296988#M62315</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-07T15:06:36Z</dc:date>
    </item>
  </channel>
</rss>

