<?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: Case when to handle blank and NULL values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914463#M360348</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;What if both Zip and Zip_Plus is missing?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2024 04:57:44 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2024-02-05T04:57:44Z</dc:date>
    <item>
      <title>Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914436#M360332</link>
      <description>&lt;P&gt;Below case when is correct to handle, "If the values are not available or only ZIP is available then I do not want to populate hyphen "-".?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;case when ZIP IS NULL or&amp;nbsp; ' '&amp;nbsp; then ZIP||ZIP_PLUS&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ZIP_PLUS IS NULL or&amp;nbsp; ' '&amp;nbsp; then ZIP||ZIP_PLUS&lt;BR /&gt;else ZIP||'-'||ZIP_PLUS&lt;BR /&gt;end as PRO_ZIP&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 17:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914436#M360332</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2024-02-04T17:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914438#M360334</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Below case when is correct to handle, "If the values are not available or only ZIP is available then I do not want to populate hyphen "-".?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;case when ZIP IS NULL or&amp;nbsp; ' '&amp;nbsp; then ZIP||ZIP_PLUS&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ZIP_PLUS IS NULL or&amp;nbsp; ' '&amp;nbsp; then ZIP||ZIP_PLUS&lt;BR /&gt;else ZIP||'-'||ZIP_PLUS&lt;BR /&gt;end as PRO_ZIP&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure what question you are asking. Are you saying the code you provided does not work? Are you saying it does something but not what you want? Are you asking something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the correct answers for these cases?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. ZIP=53408 ZIP_PLUS=&lt;/P&gt;
&lt;P&gt;2. ZIP= ZIP_PLUS=3483&lt;/P&gt;
&lt;P&gt;3. ZIP=53408 ZIP_PLUS=3483&lt;/P&gt;
&lt;P&gt;4. ZIP= ZIP_PLUS=&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 17:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914438#M360334</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-04T17:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914439#M360335</link>
      <description>&lt;P&gt;This could be a good use-case for the CATX function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  input zip $5. zip_plus $4.;

  length want $10 ;
  want=catx('-',zip,zip_plus) ;

  cards ;
12345 1234
.     1234
12345 .
;

proc print ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;Obs     zip     zip_plus    want

 1     12345      123       12345-123
 2                123       123
 3     12345                12345
&lt;/PRE&gt;
&lt;P&gt;But your interpretation of the specification seems surprising.&amp;nbsp; If zip is missing, I don't think there is value in having the&amp;nbsp; value for zip_plus. So for row2, I would want the result be blank (because I don't know the actual zip code), rather than '123'.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 17:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914439#M360335</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-02-04T17:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914440#M360336</link>
      <description>&lt;P&gt;Since SAS uses fixed length character variables there is no difference between missing (what SQL syntax means by NULL) and a value that is all spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first point is that the OR operator is a BINARY operator.&amp;nbsp; It takes TWO arguments, one on the LEFT and one on the RIGHT.&amp;nbsp; So this code is invalid (or at least illogical).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ZIP IS NULL or  ' '  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you put in parentheses like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; (ZIP IS NULL) or  (' ' )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are asking the OR operator to treat that character string as a BOOLEAN value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you put in parentheses like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ZIP IS (NULL or ' ')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are asking the OR operator generate BOOLEAN value (0 or 1).&amp;nbsp; Since NULL and ' ' are both missing values then the result should be 0 (FALSE).&amp;nbsp; So&amp;nbsp; the code is testing whether ZIP is equal to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally it looks like you are just trying to replicate the CATX() function, but perhaps without the removal of the trailing spaces from the first value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;catx('-',ZIP,ZIP_PLUS) as PRO_ZIP&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you probably do not what that when ZIP is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when not missing(zip) then catx('-',ZIP,ZIP_PLUS) 
  else ' '
end as PRO_ZIP length=10&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if ZIP and ZIP_PLUS are NUMERIC then you might need to format them so the leading zeros don't get removed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(zip) then ' '
     when missing(zip_plus) then put(zip,z5.)
     else put(zip,z5.)||'-'||put(zip_plus,z4.)
end as PRO_ZIP length=10&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Feb 2024 18:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914440#M360336</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-04T18:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914462#M360347</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; May I know how to tweak/extend the following code to handle both the conditions at the same time? Both Zip and Zip_Pllus is character datatype.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to do this,&amp;nbsp;&lt;STRONG&gt;catx('-',ZIP,ZIP_PLUS)&lt;/STRONG&gt; only when ZIP and/or ZIP_PLUS is missing or NULL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;case when not missing(zip) then catx('-',ZIP,ZIP_PLUS) 
  else ' '
end as PRO_ZIP length=10&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 04:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914462#M360347</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2024-02-05T04:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914463#M360348</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;What if both Zip and Zip_Plus is missing?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 04:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914463#M360348</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2024-02-05T04:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914474#M360352</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Handling-Missing-and-Null-Values/m-p/914472#M360351" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Handling-Missing-and-Null-Values/m-p/914472#M360351&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 09:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914474#M360352</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-05T09:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914487#M360358</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;What if both Zip and Zip_Plus is missing?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The great thing about having a small test data set and example code is that when you have a "what if" question, you can add the scenario to your example and see what happens.&amp;nbsp; Here I added a 4th record with Zip and Zip_Plus missing.&amp;nbsp; I'll leave it to you to run the code and explore the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  input zip $5. zip_plus $4.;

  length want $10 ;
  want=catx('-',zip,zip_plus) ;

  cards ;
12345 1234
.     1234
12345 .
.     .
;

proc print ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 13:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914487#M360358</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-02-05T13:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Case when to handle blank and NULL values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914495#M360359</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; May I know how to tweak/extend the following code to handle both the conditions at the same time? Both Zip and Zip_Pllus is character datatype.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to do this,&amp;nbsp;&lt;STRONG&gt;catx('-',ZIP,ZIP_PLUS)&lt;/STRONG&gt; only when ZIP and/or ZIP_PLUS is missing or NULL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;case when not missing(zip) then catx('-',ZIP,ZIP_PLUS) 
  else ' '
end as PRO_ZIP length=10&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you leave out a NOT?&amp;nbsp; It makes no sense to want to use CATX() only when the values &lt;STRONG&gt;are&lt;/STRONG&gt; missing.&amp;nbsp; If either (or both) of them is missing then the hyphen is not added.&amp;nbsp; So if ZIP is NOT missing and ZIP_PLUS is missing the result of CATX('-',zip,zip_plus) is just the value of ZIP, which is what people would normally use when addressing mail in that situation.&amp;nbsp; &amp;nbsp;When ZIP and ZIP_PLUS are both NOT missing then you get the hyphen inserted between them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note it makes no sense to use the value of ZIP_PLUS if the value of ZIP is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it and see what it does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(note MISSING and NULL mean the same thing).&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 14:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-to-handle-blank-and-NULL-values/m-p/914495#M360359</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-05T14:27:58Z</dc:date>
    </item>
  </channel>
</rss>

