<?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: how to test if a value is an element of a format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573144#M161767</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;A similar concept using a custom informat when reading external data can be used either something like:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $A
    '00','01','02','03','04'= _same_
    other=_error_
  ;
run;&lt;/PRE&gt;
&lt;P&gt;and read the data using the $A. informat. If a value other than those listed is encountered you get an invalid data message and diagnostics wth the value set to missing for the non-listed values.&lt;/P&gt;
&lt;P&gt;Or if your would actually prefer to have the formatted values as the actual value then read the data as such:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $A
    '00'="00"
    '01'="foo"
    '02'="bar"
    '03'="sna"
    '04'="fu"
    other=_error_
  ;
run;&lt;/PRE&gt;
&lt;P&gt;which again has the invalid data diagnostics for non listed values.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You learn something new everyday, that's an awesomely useful feature, thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jul 2019 15:32:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-12T15:32:11Z</dc:date>
    <item>
      <title>how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573062#M161742</link>
      <description>&lt;P&gt;I have a series of formats like the one below, in different catalogs.&amp;nbsp; They are string and numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $A
    '00'="00"
    '01'="foo"
    '02'="bar"
    '03'="sna"
    '04'="fu"
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How, easy way and hard way, does one test if the &lt;STRONG&gt;put&lt;/STRONG&gt;() function will return a mapped value and not just pass through the value of the first parameter that is unmatched?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have faith that SAS has a function for or some syntax solution for this, yet I don't quite know how to google it here or there.&amp;nbsp; Any clue or idea would help.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 12:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573062#M161742</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2019-07-12T12:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573063#M161743</link>
      <description>&lt;P&gt;Given your example NO.&lt;/P&gt;
&lt;P&gt;Normally I would just test if the formatted value matches the unformatted value to tell if the format did anything.&amp;nbsp; But your format leaves 00 unchanged.&amp;nbsp; Also that won't work for numeric formats since everything is changed because the format will convert numbers to text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the definition of the format out into a dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format lib=libref.catname cntlout=myformats; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the format are simple lists like your example you could then just check if the value you have matches one of the START value for the format in question.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 12:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573063#M161743</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-12T12:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573073#M161745</link>
      <description>&lt;P&gt;Wow, I was afraid of that.&amp;nbsp; I was hoping that there was something. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dream of a put function that does this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result; 
  do x = '00', 'AA'; 
    y=put(x,?$A.); *Question mark a la input();
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;result:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;x  y&lt;/STRONG&gt;  
00 00
AA &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 12:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573073#M161745</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2019-07-12T12:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573092#M161751</link>
      <description>&lt;P&gt;Change how your format is defined to include the OTHER option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 value $a 
   '00'='00'
   other=' '
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jul 2019 13:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573092#M161751</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-12T13:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573095#M161753</link>
      <description>&lt;P&gt;I think you're right.&amp;nbsp; I'll mark this solved soon.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 13:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573095#M161753</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2019-07-12T13:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573126#M161761</link>
      <description>I use the Other = "CHECKME" in most code to have errors jump out at me...I don't always catch it but it's a pretty obvious mistake and I know where to look right away.</description>
      <pubDate>Fri, 12 Jul 2019 15:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573126#M161761</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-12T15:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573133#M161762</link>
      <description>&lt;P&gt;That seems to be a good practice to keep.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 15:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573133#M161762</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2019-07-12T15:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573141#M161766</link>
      <description>&lt;P&gt;A similar concept using a custom informat when reading external data can be used either something like:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $A
    '00','01','02','03','04'= _same_
    other=_error_
  ;
run;&lt;/PRE&gt;
&lt;P&gt;and read the data using the $A. informat. If a value other than those listed is encountered you get an invalid data message and diagnostics wth the value set to missing for the non-listed values.&lt;/P&gt;
&lt;P&gt;Or if your would actually prefer to have the formatted values as the actual value then read the data as such:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $A
    '00'="00"
    '01'="foo"
    '02'="bar"
    '03'="sna"
    '04'="fu"
    other=_error_
  ;
run;&lt;/PRE&gt;
&lt;P&gt;which again has the invalid data diagnostics for non listed values.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 15:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573141#M161766</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-12T15:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573144#M161767</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;A similar concept using a custom informat when reading external data can be used either something like:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $A
    '00','01','02','03','04'= _same_
    other=_error_
  ;
run;&lt;/PRE&gt;
&lt;P&gt;and read the data using the $A. informat. If a value other than those listed is encountered you get an invalid data message and diagnostics wth the value set to missing for the non-listed values.&lt;/P&gt;
&lt;P&gt;Or if your would actually prefer to have the formatted values as the actual value then read the data as such:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $A
    '00'="00"
    '01'="foo"
    '02'="bar"
    '03'="sna"
    '04'="fu"
    other=_error_
  ;
run;&lt;/PRE&gt;
&lt;P&gt;which again has the invalid data diagnostics for non listed values.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You learn something new everyday, that's an awesomely useful feature, thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 15:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573144#M161767</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-12T15:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to test if a value is an element of a format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573147#M161769</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;I'm glad I didn't close this out right after Tom responded, thanks for your contributions.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 15:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-test-if-a-value-is-an-element-of-a-format/m-p/573147#M161769</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2019-07-12T15:38:34Z</dc:date>
    </item>
  </channel>
</rss>

