<?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 Is there a function or setting to make a user-defined format return blank if no match? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/325838#M271479</link>
    <description>&lt;P&gt;Normally when you use put(var, format), it will either return the corresponding label or the original value if there is no match in the format.&amp;nbsp; However, returning the original value defeats the purpose of using user-defined formats in many cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody know if there's a "clean" or "built-in" way to force the put statement (or some other function) to return a blank or null instead of the original value when the format has no match?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if we're using a zip to city format called $zip_city:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; zip &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;43765&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;city = put(zip, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$zip_city.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code returns city = 43765 (since that zip does not exist in the US yet), but I'd&amp;nbsp;like a blank or null returned.&amp;nbsp;&amp;nbsp;I can always force a blank return with an if statement (if put(zip, $zip_city.)=zip then city=.), but if anybody can enlighten me with a better way I'd really appreciate it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jan 2017 23:11:41 GMT</pubDate>
    <dc:creator>azhou_uhg</dc:creator>
    <dc:date>2017-01-18T23:11:41Z</dc:date>
    <item>
      <title>Is there a function or setting to make a user-defined format return blank if no match?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/325838#M271479</link>
      <description>&lt;P&gt;Normally when you use put(var, format), it will either return the corresponding label or the original value if there is no match in the format.&amp;nbsp; However, returning the original value defeats the purpose of using user-defined formats in many cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody know if there's a "clean" or "built-in" way to force the put statement (or some other function) to return a blank or null instead of the original value when the format has no match?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if we're using a zip to city format called $zip_city:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; zip &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;43765&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;city = put(zip, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$zip_city.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code returns city = 43765 (since that zip does not exist in the US yet), but I'd&amp;nbsp;like a blank or null returned.&amp;nbsp;&amp;nbsp;I can always force a blank return with an if statement (if put(zip, $zip_city.)=zip then city=.), but if anybody can enlighten me with a better way I'd really appreciate it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 23:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/325838#M271479</guid>
      <dc:creator>azhou_uhg</dc:creator>
      <dc:date>2017-01-18T23:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a function or setting to make a user-defined format return blank if no match?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/325843#M271480</link>
      <description>&lt;P&gt;There are two methods to do what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) &amp;nbsp;if formated value = original value then clear it to blank.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;the syntax for numeric origin and for alphanumeric origin is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) cange the format to include&amp;nbsp;&lt;STRONG&gt;other&lt;/STRONG&gt; option, for example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value test
       1 = 'A'
       2 = 'B'
       3 = 'C'
    &lt;STRONG&gt;other&lt;/STRONG&gt; = ' '
; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;in a case you have a format and you can't ot not allowed to change it &amp;nbsp;- add the&amp;nbsp;&lt;STRONG&gt;other&lt;/STRONG&gt;&amp;nbsp;option,&lt;/P&gt;
&lt;P&gt;then you can create a variation in work (temporary) catalog:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format lib=mylib cntlout=cntl;
    select myfmt;
run;

data cntl;
  set cntl end=eof;
        output;
        if eof then do;
           OLH = 'O';    /* O=other, L=low, H=high */
           label = ' ';
           output;
       end;
run;

proc format lib=work cntlin=cntl; run;

options fmtsearch = (work mylib);
        &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 10:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/325843#M271480</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-19T10:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a function or setting to make a user-defined format return blank if no match?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/327068#M271481</link>
      <description>&lt;P&gt;Thank you for your advice, Shmuel!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently using the first method you suggested (an if statement) as it seems to be the fastest/cleanest way so far.&amp;nbsp; I was wondering if there is a "built-in" option to use for returning a user-specified negative reply instead of the automatic one.&amp;nbsp; It does not seem like there is, so thank you anyway.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 14:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/327068#M271481</guid>
      <dc:creator>azhou_uhg</dc:creator>
      <dc:date>2017-01-24T14:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a function or setting to make a user-defined format return blank if no match?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/327139#M271482</link>
      <description>&lt;P&gt;Have you used or trird to use the option&amp;nbsp;&lt;STRONG&gt;other&lt;/STRONG&gt; in your format ?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 18:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/327139#M271482</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-24T18:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a function or setting to make a user-defined format return blank if no match?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/327142#M271483</link>
      <description>&lt;P&gt;Oh, my&amp;nbsp;bad.&amp;nbsp; I understand now.&amp;nbsp; The &lt;STRONG&gt;other&lt;/STRONG&gt; tag isn't just for the exact match of "other".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That should do it then.&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 18:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-function-or-setting-to-make-a-user-defined-format/m-p/327142#M271483</guid>
      <dc:creator>azhou_uhg</dc:creator>
      <dc:date>2017-01-24T18:53:04Z</dc:date>
    </item>
  </channel>
</rss>

