<?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 Using IF condition while using PUT function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435384#M108177</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i Have dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Sex Age Date Height Weight Fee&lt;BR /&gt;2458 M 27 1 72 168 85.2&lt;BR /&gt;2462 F 34 3 66 152 124.8&lt;BR /&gt;2501 F 31 17 61 123 149.75&lt;BR /&gt;2523 F 43 31 63 137 149.75&lt;BR /&gt;2539 M 51 4 71 158 124.8&lt;BR /&gt;2544 M 29 6 76 193 124.8&lt;BR /&gt;2552 F 32 9 67 151 149.75&lt;BR /&gt;2555 M 35 13 70 173 149.75&lt;BR /&gt;2563 M 34 22 73 154 124.8&lt;BR /&gt;2568 F 49 27 64 172 124.8&lt;BR /&gt;2571 F 44 19 66 140 149.75&lt;BR /&gt;2572 F 28 17 62 118 85.2&lt;BR /&gt;2574 M 30 6 69 147 149.75&lt;BR /&gt;2575 F 40 8 69 163 124.8&lt;BR /&gt;2578 M 47 5 72 173 124.8&lt;BR /&gt;2579 M 60 22 71 191 149.75&lt;BR /&gt;2584 F 43 29 65 123 124.8&lt;BR /&gt;2586 M 25 23 75 188 85.2&lt;BR /&gt;2588 F 22 20 63 139 85.2&lt;BR /&gt;2589 F 41 16 67 141 149.75&lt;BR /&gt;2595 M 54 7 71 183 149.75&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say if i run a code like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data a;&lt;BR /&gt;set sasuser.admit;&lt;BR /&gt;per=age/fee;&lt;/P&gt;&lt;P&gt;form=put(per,percent9.2);&lt;/P&gt;&lt;P&gt;if form gt "30%";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will not give any observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know how we can use the If condition on the format we used in PUT function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 19:02:48 GMT</pubDate>
    <dc:creator>shivamarrora0</dc:creator>
    <dc:date>2018-02-08T19:02:48Z</dc:date>
    <item>
      <title>Using IF condition while using PUT function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435384#M108177</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i Have dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Sex Age Date Height Weight Fee&lt;BR /&gt;2458 M 27 1 72 168 85.2&lt;BR /&gt;2462 F 34 3 66 152 124.8&lt;BR /&gt;2501 F 31 17 61 123 149.75&lt;BR /&gt;2523 F 43 31 63 137 149.75&lt;BR /&gt;2539 M 51 4 71 158 124.8&lt;BR /&gt;2544 M 29 6 76 193 124.8&lt;BR /&gt;2552 F 32 9 67 151 149.75&lt;BR /&gt;2555 M 35 13 70 173 149.75&lt;BR /&gt;2563 M 34 22 73 154 124.8&lt;BR /&gt;2568 F 49 27 64 172 124.8&lt;BR /&gt;2571 F 44 19 66 140 149.75&lt;BR /&gt;2572 F 28 17 62 118 85.2&lt;BR /&gt;2574 M 30 6 69 147 149.75&lt;BR /&gt;2575 F 40 8 69 163 124.8&lt;BR /&gt;2578 M 47 5 72 173 124.8&lt;BR /&gt;2579 M 60 22 71 191 149.75&lt;BR /&gt;2584 F 43 29 65 123 124.8&lt;BR /&gt;2586 M 25 23 75 188 85.2&lt;BR /&gt;2588 F 22 20 63 139 85.2&lt;BR /&gt;2589 F 41 16 67 141 149.75&lt;BR /&gt;2595 M 54 7 71 183 149.75&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say if i run a code like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data a;&lt;BR /&gt;set sasuser.admit;&lt;BR /&gt;per=age/fee;&lt;/P&gt;&lt;P&gt;form=put(per,percent9.2);&lt;/P&gt;&lt;P&gt;if form gt "30%";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will not give any observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know how we can use the If condition on the format we used in PUT function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435384#M108177</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2018-02-08T19:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF condition while using PUT function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435393#M108178</link>
      <description>&lt;P&gt;Yes, but the IF statement needs to be valid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case you've converted it to a character variable, so searching for values greater than 30% in character variables may not be what you want. Is this what you want by chance?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
set sasuser.admit;
per=age/fee;
format per percent12.2;
if per gt 0.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435393#M108178</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T19:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF condition while using PUT function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435400#M108182</link>
      <description>&lt;P&gt;You already got an answer from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;about what you should be doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's why what you did isn't returning any observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When comparing character strings, SAS does not make a numeric comparison.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"12345" &amp;lt; "30"&amp;nbsp; because the first character of "12345" is less than the first character of "30"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"5" &amp;gt; "30" because the first character of "5" is greater than the first character of "30"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS looks at the first character only, to determine which string is greater.&amp;nbsp; If the first characters are equal, only then does SAS move on to the second character in order to break the tie.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's half the story.&amp;nbsp; But there's still the question of why your program returned no observations at all.&amp;nbsp; That's a result of using the percent format.&amp;nbsp; The percent format always generates character strings with a leading and a trailing blank.&amp;nbsp; The output from the percent function is always less than "30%" because blank is less than "3".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To answer your question about can you do this?&amp;nbsp; The program you ran didn't generate any error messages.&amp;nbsp; It just gave the wrong answer.&amp;nbsp; Expect that to be the result.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435400#M108182</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-08T20:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF condition while using PUT function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435406#M108183</link>
      <description>&lt;P&gt;i want to know how i can use the filter&amp;nbsp; after applying PUT function&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435406#M108183</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2018-02-08T19:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF condition while using PUT function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435457#M108198</link>
      <description>&lt;P&gt;Actually the leading and trailing blanks are to allow for the () when the value is negative:&lt;/P&gt;
&lt;PRE&gt;data example;
   x= -0.12345;
   y = put(x,percent12.3);
run;&lt;/PRE&gt;
&lt;P&gt;Since many of us don't generate negative percentages it isn't obvious.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the results to left justify with&lt;/P&gt;
&lt;P&gt;y=put(x,percent12.3 -L);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;points out greater than or less than comparisons with character values are generally a poor idea.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 21:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435457#M108198</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-08T21:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF condition while using PUT function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435559#M108218</link>
      <description>&lt;P&gt;Try this.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Build HAVE table */&lt;BR /&gt;data HAVE;
  do i=1 to 10 BY 0.01;
     output;
  end;
run;&lt;BR /&gt;&lt;BR /&gt;data WANT;&lt;BR /&gt;  set HAVE(where=(i/10 gt 0.3));&lt;BR /&gt;   FORM=put(i/10,percent9.2);&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 09:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-condition-while-using-PUT-function/m-p/435559#M108218</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2018-02-09T09:02:51Z</dc:date>
    </item>
  </channel>
</rss>

