<?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: Why can't the missing function recognize an empty string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737811#M230049</link>
    <description>&lt;P&gt;That's because your variable comment contains tabs as well and though is not missing.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1619676790373.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58844i3EED4E992FB04805/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1619676790373.png" alt="Patrick_0-1619676790373.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Added to the end for your code using the sample data you've posted:&lt;/P&gt;
&lt;PRE&gt;  put comment= $hex10.;&lt;/PRE&gt;
&lt;P&gt;Comment=&lt;FONT color="#FF0000"&gt;0909&lt;/FONT&gt;202020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could remove all non-printable characters prior to using the missing() function.&lt;/P&gt;
&lt;PRE&gt;if not missing(compress(Comment,,'w'));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;....or use prxchange() at the beginning of your code an replace all unprintable characters with a blank.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Apr 2021 06:28:24 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-04-29T06:28:24Z</dc:date>
    <item>
      <title>Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737807#M230047</link>
      <description>&lt;P&gt;I would be most grateful if someone could help me to identfify empty strings when the missing function seems not capable of doing this. In my program, a text file is read, the resulting strings are divided into parts, and the missing function is applied to identify non-empty parts. However, empty parts are not always recognized and rows are erroneously kept in the data. Program is run in SAS EG 8.2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in "C:\Temp\Data to read.txt";

data work.data
(keep=Text);
infile in lrecl=200 dsd truncover;
input
@ 1 FirstChar $ 1.
@ 1 Text $ 200.
;
if 'A' &amp;lt;= firstChar &amp;lt;= 'Z' or firstChar in('1', '2');
if firstChar not in (' ', '-', '©');
run;

data work.Data2;
length Text Text2 $ 200 ProductCode $ 6 Comment $ 200 ;
set work.data;
if _N_ = 1
then
do;
retain produktkod_re;
regexp = "/[A-Z][A-Z]\d\d\d\d/";
produktkod_re = prxparse(regexp);
end;
/* Identify product code */
if prxmatch(produktkod_re, Text)
then
do;
which_format = prxparen(produktkod_re);
call prxposn(produktkod_re, which_format, pos, len);
/* Text2 contains everything from Text except what is before product code */
Text2 = substr(Text, pos);

ProductCode = substr(Text2, 1, 6);

/* Comment contains everything efter product code */
Comment = substr(Text2, 7);
end;

/* Exclude all lines where comment is missing */
if not missing(Comment);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Apr 2021 05:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737807#M230047</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2021-04-29T05:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737811#M230049</link>
      <description>&lt;P&gt;That's because your variable comment contains tabs as well and though is not missing.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1619676790373.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58844i3EED4E992FB04805/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1619676790373.png" alt="Patrick_0-1619676790373.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Added to the end for your code using the sample data you've posted:&lt;/P&gt;
&lt;PRE&gt;  put comment= $hex10.;&lt;/PRE&gt;
&lt;P&gt;Comment=&lt;FONT color="#FF0000"&gt;0909&lt;/FONT&gt;202020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could remove all non-printable characters prior to using the missing() function.&lt;/P&gt;
&lt;PRE&gt;if not missing(compress(Comment,,'w'));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;....or use prxchange() at the beginning of your code an replace all unprintable characters with a blank.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 06:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737811#M230049</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-29T06:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737944#M230105</link>
      <description>&lt;P&gt;Even without &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s code it is possible to tell that you likely have other than space characters at the end of the second line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Opening that text file in Notepad, going to the end of the first line (cursor in first column and press End) and then doing the same to the next line shows a lot more space after the visible text and the cursor. Hitting the left arrow key to "back up one space" jumps a bunch of space for one character which is the typical behavior when TAB characters are present.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 15:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737944#M230105</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-29T15:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737965#M230113</link>
      <description>&lt;P&gt;Try adding the EXPANDTABS option to your INFILE statement so that SAS will automatically convert the tab characters into the number of spaces needed to move to the next tab stop.&amp;nbsp; The second IF statement is not needed as non of those characters could make it past the first IF statement.&amp;nbsp; Also don't add a space into the middle of you informats.&amp;nbsp; SAS will interpret that as two tokens.&amp;nbsp; The first is the bare $ of the INPUT statement that tells it to define the variable has character if the type has not already been determined.&amp;nbsp; The second is the informat.&amp;nbsp; SAS will silently to add the missing $ to your informat since it now knows you want the variable to be character because of the other part of your input statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.data;
  infile in lrecl=200 expandtabs truncover;
  input 
    @1 FirstChar $1.
    @1 Text $200.
  ;
  if 'A' &amp;lt;= firstChar &amp;lt;= 'Z' or firstChar in('1', '2');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that SAS is silently change the type of the informat (or format) went the conversion means it is not found.&lt;/P&gt;
&lt;PRE&gt;985   data test;
986     length x $9;
987     input x date9. ;
                ------
                485
NOTE 485-185: Informat &lt;STRONG&gt;$DATE&lt;/STRONG&gt; was not found or could not be loaded.
&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Apr 2021 17:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737965#M230113</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-29T17:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737979#M230122</link>
      <description>&lt;P&gt;Thanks for all the good information provided!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I choose Patrick's answer as solution as it is an exact reply to the question posed. However, Tom's solution is more elegant and it is this proposal that I'm going to implement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 17:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/737979#M230122</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2021-04-29T17:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/738050#M230160</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13363"&gt;@Multipla99&lt;/a&gt;&amp;nbsp;Given your response and what you've shown us below should work as well for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let regex=\b([A-Z]{2}\d{4})\b;

filename in "C:\Temp\Data to read.txt";
data want(drop=_:);
  infile in lrecl=200 expandtabs truncover;
  input _firstChar $1. @1 str $200.;
  if findc(_firstChar,'12','a')=1;

  length ProductCode $6 cmt $200;
  label cmt='Comment';

  if _n_ = 1 then
    do;
      retain _rxp_id;
      _rxp_id = prxparse("/&amp;amp;regex/");
    end;

  /* Identify product code */
  _pos=prxmatch(_rxp_id, str);
  if _pos&amp;gt;0 then
    do;
      ProductCode=prxposn(_rxp_id,1,str);
      cmt=substrn(str,_pos+lengthn(ProductCode));
      if not missing(cmt) then output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 May 2021 03:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/738050#M230160</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-05-01T03:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't the missing function recognize an empty string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/738234#M230240</link>
      <description>&lt;P&gt;Thank you, Patrick! Very neat and elegante. Hut ab!&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 17:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-can-t-the-missing-function-recognize-an-empty-string/m-p/738234#M230240</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2021-04-30T17:38:33Z</dc:date>
    </item>
  </channel>
</rss>

