<?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: [Question] Use Proc Format to replace if-then/else in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305298#M60911</link>
    <description>&lt;P&gt;First, assigning a format will not change the value, so for purposes like using it in a condition, the variable stays the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your format, the result will be a dot in all cases, so that won't work either. Also keep in mind that the result of a value format is always of type character, never numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your simple&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a &amp;gt; 2 then a = .;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the best solution. Stay with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: and if you also want to exclude values &amp;lt; 0, do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a &amp;gt; 2 or a &amp;lt; 0 then a = .;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Oct 2016 07:06:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-10-18T07:06:06Z</dc:date>
    <item>
      <title>[Question] Use Proc Format to replace if-then/else</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305290#M60909</link>
      <description>&lt;P&gt;Hello, guys.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about the PROC format, and I'm using SAS 9.4 under windows.&lt;/P&gt;&lt;P&gt;Below is my original data code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA one;&lt;BR /&gt;INPUT A :10. B :$;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 A&lt;BR /&gt;1.1 B&lt;BR /&gt;1.3 C&lt;BR /&gt;10 D&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;DATA two;&lt;BR /&gt;SET one;&lt;BR /&gt;IF A&amp;gt;2 then A=.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The objective is to check if A is in the range of (0,2) or not, if A isn't in the range, let A be null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below&amp;nbsp;was what I thought might work using PROC FORMAT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA one;&lt;BR /&gt;INPUT A :10. B :$;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 A&lt;BR /&gt;1.1 B&lt;BR /&gt;1.3 C&lt;BR /&gt;10 D&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc format;&lt;BR /&gt;Value num&lt;BR /&gt;low-0=.&lt;BR /&gt;2-high=.&lt;BR /&gt;other=.&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data three;&lt;BR /&gt;SET one;&lt;BR /&gt;FORMAT A num.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, it didn't.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any one has any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 06:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305290#M60909</guid>
      <dc:creator>JinZhou</dc:creator>
      <dc:date>2016-10-18T06:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: [Question] Use Proc Format to replace if-then/else</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305298#M60911</link>
      <description>&lt;P&gt;First, assigning a format will not change the value, so for purposes like using it in a condition, the variable stays the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your format, the result will be a dot in all cases, so that won't work either. Also keep in mind that the result of a value format is always of type character, never numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your simple&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a &amp;gt; 2 then a = .;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the best solution. Stay with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: and if you also want to exclude values &amp;lt; 0, do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a &amp;gt; 2 or a &amp;lt; 0 then a = .;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2016 07:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305298#M60911</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-18T07:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: [Question] Use Proc Format to replace if-then/else</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305300#M60912</link>
      <description>&lt;P&gt;Thank you Kurt. Your reply is always fast and straight.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But by the way, I have to a massive data cleaning process for each variable like this one. (Mass = 900+)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These Variables include character, number+character strings(like license), numbers strings(like phone number), intervals, etc..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a quick and simple way I can use? Just like proc format, I could just define it in one bulk step with my data dictionary, and apply it over and over to each variable whenever I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot Kurt.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 07:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305300#M60912</guid>
      <dc:creator>JinZhou</dc:creator>
      <dc:date>2016-10-18T07:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: [Question] Use Proc Format to replace if-then/else</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305309#M60913</link>
      <description>&lt;P&gt;As I said, just applying a format won't solve your issue (reliably), as the values stay the same. You could use an informat in an input() function, but I'd rather write a macro for the correction, and call that macro with call execute() from a datastep that uses a dataset created from sashelp.vcolumn.&lt;/P&gt;
&lt;P&gt;Creating lots of formats might overload your internal format dictionary, and that may well cause performance issues.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 08:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305309#M60913</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-18T08:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: [Question] Use Proc Format to replace if-then/else</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305396#M60920</link>
      <description>&lt;P&gt;A FORMAT may not be the answer but an INFORMAT might if you want to change numeric to numeric. Then use an INPUT statement with text value of your variable and the informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
invalue dummy
0  - &amp;lt; 10 = 1
10 - &amp;lt; 100 = 2
100 - high = 3;
run;

data example;
   input x;
datalines;
1
9
15
1233
4444444
;

data want;
   set example;
   x = input(put(x,best12.),dummy.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could actually use x instead of put(x,best12.) but you'll get "NOTE: Numeric values have been converted to character values at the places given by:" in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 14:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Question-Use-Proc-Format-to-replace-if-then-else/m-p/305396#M60920</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-18T14:36:54Z</dc:date>
    </item>
  </channel>
</rss>

