<?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: blank values of a query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851403#M336519</link>
    <description>&lt;P&gt;Overwriting the source dataset during development is not recommended. It is always better to create a new dataset, so that steps are repeatable. The first thing you should to is re-creating "mydata". Then please post some lines of that dataset as data step, so we have actually see the data you have.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Dec 2022 20:43:33 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-12-28T20:43:33Z</dc:date>
    <item>
      <title>blank values of a query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851401#M336517</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am creating a new column called "group" in my dataset based on the value of another column. The real code I run has many more if conditions but the "group" column has only 3 values; indeterminate, not performance, performance.&amp;nbsp; The 'reason' has no blank values in mydata.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data mydata;
set mydata;
	if reason = "asd asd asd" then group = "indeterminate";
	if reason = "abc abc abc" then group = "indeterminate";
	if reason= "xxx" then group="not performance";     
        if reason= "yy" then group="performance"; 
	if cancellation_reason="" then cancellation_grouping="missing";
run;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;In the output, some certain group values are blank. They didn't get assigned to any of the 3 values.&lt;BR /&gt;&lt;BR /&gt;For example, assume the reason "asd asd asd" is one of the values of 'reason' with blank 'group' in the output. Then I search for it in the data, it does not return any output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select reason, group
from mydata
where reason = 'asd asd asd' ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Somehome, the data seems it does not have this 'asd asd asd' value in the 'reason' column eventhough I exactly copy-pasted from the data itself. What could be the reason for this and how to solve it?&amp;nbsp;&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 20:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851401#M336517</guid>
      <dc:creator>znhnm</dc:creator>
      <dc:date>2022-12-28T20:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: blank values of a query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851403#M336519</link>
      <description>&lt;P&gt;Overwriting the source dataset during development is not recommended. It is always better to create a new dataset, so that steps are repeatable. The first thing you should to is re-creating "mydata". Then please post some lines of that dataset as data step, so we have actually see the data you have.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 20:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851403#M336519</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-12-28T20:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: blank values of a query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851461#M336545</link>
      <description>&lt;P&gt;Casing or leading blanks could be the issue. Some code like below should help to avoid such issues.&lt;/P&gt;
&lt;P&gt;Use IF...THEN...ELSE constructs for cases like yours and always implement exhaustive conditions having a final ELSE without an IF to capture everything that remains (like exceptions).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  set mydata;
  length group $20;
  _reason=upcase(strip(reason));
  drop _reason;
  if _reason in ("asd asd asd","abc abc abc") then group = "indeterminate";
  else if _reason= "xxx" then group="not performance";     
  else if _reason= "yy" then group="performance"; 
  else group='ERROR';

  if missing(cancellation_reason) then cancellation_grouping="missing";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using formats is another way to code such IF...THEN...ELSE constructs. Such an approach can increase "readability" and "maintainability" of your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $group
    "ASD ASD ASD","ABC ABC ABC" = "indeterminate"
    "XXX"   = "not performance"
    "YY"    = "performance"
    other   = "ERROR"
  ;
run;

data mydata;
  set mydata;
  group=put(upcase(strip(reason)),$group.);
	if missing(cancellation_reason) then cancellation_grouping="missing";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And now that you captured the exceptions you can also easier investigate and debug your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select reason, group
  from mydata
  where group='ERROR' 
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Dec 2022 02:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851461#M336545</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-29T02:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: blank values of a query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851483#M336549</link>
      <description>&lt;P&gt;I am assuming you are looking at some PRINT OUT of the values that makes you think that string is there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The usual cause is leading spaces.&amp;nbsp; Especially if the print out you looked at was generated with ODS as that REMOVES the leading spaces when it generates the print out.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if left(reason) = "asd asd asd" then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other obvious things to check.&amp;nbsp; Does the CASE of the letters agree?&amp;nbsp; ASD is a different string than asd.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if lowcase(left(reason)) = "asd asd asd" then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the harder problem is non-printing characters in the string.&amp;nbsp; So they look like spaces, but they aren't spaces. Things like tab ('09'x) or linefeed ('0A'x) or carriage return ('0D'x) or non-breaking spaces ('A0'x) .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if lowcase(left(translate(reason,' ','090A0DA0'x))) = "asd asd asd" then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or perhaps something more exotic.&amp;nbsp; To look for those print the values using the $HEX format.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2022 05:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/blank-values-of-a-query/m-p/851483#M336549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-29T05:59:10Z</dc:date>
    </item>
  </channel>
</rss>

