<?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: findw function not working correctly n proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735289#M229055</link>
    <description>Legend! Thanks Tom</description>
    <pubDate>Mon, 19 Apr 2021 15:22:15 GMT</pubDate>
    <dc:creator>robulon</dc:creator>
    <dc:date>2021-04-19T15:22:15Z</dc:date>
    <item>
      <title>findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735247#M229038</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've done quite a bit of searching online around this and can't find anything. I'm using Enterprise Guide version 7.15 on a Windows PC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a flag variable in a proc sql program to identify whether a specific character variable contains the word 'unsold'. Here is my code: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table work.test as&lt;BR /&gt;select&lt;BR /&gt;*&lt;BR /&gt;,case when findw(stop_category_description,'unsold','','i') then 1 else 0 end as unsold&lt;BR /&gt;from work.t1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I check the output dataset, there are no observations populated with 1 for the unsold variable. If however I view the output dataset in EG and click 'where' and paste the 'findw(stop_category_description,'unsold','','i')' code in, it identifies 31 observations, all of which I can see do contain the work 'unsold' in them but that are populated with a 0 for the unsold variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did see a previous post from a couple of years ago that someone had put about the findw function and the user was recommended to contact SAS Technical Services. I have a feeling this may also need their attention but thought I'd ask the community first in case there's something I'm missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always, any help will be gratefully received.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 13:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735247#M229038</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T13:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735248#M229039</link>
      <description>&lt;P&gt;Please provide a small portion (that illustrates the problem) of the data set used (WORK.T1) following these instructions (and not via any other method)&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735248#M229039</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-19T14:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735252#M229041</link>
      <description>&lt;P&gt;I'm going to struggle to do that I'm afraid as the dataset contains sensitive customer data (apologies, I had meant to include that information in my original post).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had hoped that I had provided enough information to demonstrate that the function worked within the where facility in the EG viewer but not in the code itself. I've also just tried doing the same in the source dataset (work.t1) and it has correctly identified the correct observation there as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not to worry, I can easily work around it for the time being anyway, I just thought it might be something that someone had come across before. If I can think of a way to provide the data in the required format, I will do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks anyway&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735252#M229041</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T14:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735253#M229042</link>
      <description>&lt;P&gt;Just to add, I've also coded this up in a data step: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.t3;&lt;BR /&gt;set work.t1;&lt;BR /&gt;unsold = 0;&lt;BR /&gt;if findw(stop_category_description,'unsold','','i') then unsold = 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this has worked perfectly so it seems to be something to do with how proc sql is implementing the function.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735253#M229042</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T14:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735254#M229043</link>
      <description>&lt;P&gt;No need to supply the real data. Just some example data that exhibits the issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could subset to just the variables needed for the FINDW() call and one or two observations where it fails (and if there are any then one or two where it works).&amp;nbsp; If the values of that variable are sensitive then change some of the values to make them sharable.&lt;/P&gt;
&lt;P&gt;You might find that you can can find the solution yourself in the process of creating that test data.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735254#M229043</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-19T14:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735255#M229044</link>
      <description>&lt;P&gt;I don't think you can get much help on this question without data that illustrates the problem.&amp;nbsp; Why not make some synthetic data that shows the issue?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735255#M229044</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-19T14:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735258#M229045</link>
      <description>&lt;P&gt;Thanks for the suggestions. I've not been able to download the data2datastep zip file as my work pc will not allow it but have looked to recreate the issue using some datalines code (hope that's ok): -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data l1;&lt;BR /&gt;input stop_category_description $30.;&lt;BR /&gt;datalines;&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Post Covid Arrangement Agreed&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;New VT Unsold&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Post Covid&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Post Covid Arrangement Agreed&lt;BR /&gt;Post Covid&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;New Repossession Unsold&lt;BR /&gt;New Repossession Unsold&lt;BR /&gt;New VT Unsold&lt;BR /&gt;Post Covid Arrangement Agreed&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Post Covid&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Covid Customer Care&lt;BR /&gt;Post Covid Arrangement Agreed&lt;BR /&gt;New VT Unsold&lt;BR /&gt;Post Covid Arrangement Agreed&lt;BR /&gt;New IVA&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table l2 as&lt;BR /&gt;select&lt;BR /&gt;stop_category_description&lt;BR /&gt;,case when findw(stop_category_description,'unsold','','i') then 1 else 0 end as unsold&lt;BR /&gt;from l1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data l3;&lt;BR /&gt;set l1;&lt;BR /&gt;if findw(stop_category_description,'unsold','','i') then unsold = 1;&lt;BR /&gt;else unsold = 0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I run these three programs, the proc sql one does not populate the 'unsold' variable with any 1 values whereas when I do the same in the data step, it correctly identifies them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I say, I can work around it anyway but I like to understand why things don't work as for the most part, it's because I'm doing something incorrectly and want to try to learn the right way of doing things but in this case, I'm not sure that is what's happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735258#M229045</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T14:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735260#M229047</link>
      <description>&lt;P&gt;Your problem comes from the third parameter in findw. '' , with no space, means there are NO characters in the list. If you want default delimiters don't put the string at all, if you want a blank as the only delimiter you must provide a blank in the parameter.&lt;/P&gt;
&lt;P&gt;Otherwise NO characters are used for delimiters so your whole string is the only word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a minimum sort of test case:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines missover;
   input var $25.;
datalines;
contains unsold
does not have word
;

proc sql;
create table work.test as
select
*
,case when findw(var,'unsold',' ','i') then 1 else 0 end as unsold
from work.example;
quit;&lt;/PRE&gt;
&lt;P&gt;that does set the flag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you need to remember that this forum reformats the text in the main message window and so code pasted there may not actually be what was submitted when white space characters are removed or the other reformatting applied.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735260#M229047</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-19T14:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735263#M229049</link>
      <description>&lt;P&gt;That's brilliant, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was only including the third parameter as my understanding is if you are applying a modifier, you also have to apply a delimiter parameter so that SAS knows you are intending to use the 'i' as a modifier and not a delimiter, however I hadn't appreciated that I would also need to include a space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I should have known it was me doing the wrong thing (again) but that's been really helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks ballardw and thanks to everyone for looking.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735263#M229049</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T14:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735264#M229050</link>
      <description>&lt;P&gt;Having said that, I'm still a bit confused as to why I don't need a space when doing it in a data step but I do in proc sql but I'll worry about that another time!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 14:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735264#M229050</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T14:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735288#M229054</link>
      <description>&lt;P&gt;There is a difference between data step and SQL that are impacting this.&lt;/P&gt;
&lt;P&gt;In a data step there is no way to express a literal string of length zero.&amp;nbsp; If you code two quote character next to each other the result is a string of length 1 with a single space character.&amp;nbsp; You can generate one using the TRIMN() function.&lt;/P&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   input var $25.;
   datastep1=findw(var,'unsold',' ','i') ;
   datastep2=findw(var,'unsold','','i') ;
   datastep3=findw(var,'unsold',trimn(' '),'i') ;
datalines;
unsold
contains unsold
does not have word
;

proc sql;
create table work.test as
select *
     , findw(var,'unsold',' ','i') as sql1
     , findw(var,'unsold','','i') as sql2
     , findw(var,'unsold',trimn(' '),'i') as sql3
from work.example
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    var                   datastep1    datastep2    datastep3    sql1    sql2    sql3

 1     unsold                     1            1           0          1       0       0
 2     contains unsold           10           10           0         10       0       0
 3     does not have word         0            0           0          0       0       0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 15:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735288#M229054</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-19T15:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735289#M229055</link>
      <description>Legend! Thanks Tom</description>
      <pubDate>Mon, 19 Apr 2021 15:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735289#M229055</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2021-04-19T15:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: findw function not working correctly n proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735308#M229064</link>
      <description>&lt;P&gt;Interestingly, with PROC SQL's FEEDBACK option the log incorrectly states that a single blank was interpreted as a null string, whereas the log of a DATA step correctly describes the opposite interpretation of a null string in a WHERE condition:&lt;/P&gt;
&lt;PRE&gt;648  proc sql feedback;
649  create table selsql as
650  select var from example
651  where findw(var,'unsold',' ','i');
NOTE: Statement transforms to:

        select EXAMPLE.var
          from WORK.EXAMPLE
         where FINDW(EXAMPLE.var, 'unsold', '', 'i');

NOTE: Table WORK.SELSQL created, with 2 rows and 1 columns.

652  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.13 seconds
      cpu time            0.12 seconds


653
654  data selds;
655  set example;
656  where findw(var,'unsold','','i');
657  run;

NOTE: There were 2 observations read from the data set WORK.EXAMPLE.
      WHERE FINDW(var, 'unsold', ' ', 'i');
NOTE: The data set WORK.SELDS has 2 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Apr 2021 15:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-function-not-working-correctly-n-proc-sql/m-p/735308#M229064</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-19T15:59:05Z</dc:date>
    </item>
  </channel>
</rss>

