<?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 Need SAS data step logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327614#M73087</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data as below and need&amp;nbsp;to find out which CUSTOMER has given a "5" score and then immediately followed with a missing score. can you please suggest how to achive this in Data step.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;SCORE&lt;/TD&gt;&lt;TD&gt;COMMENT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;I like the food&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;The service is very bad&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;The is no parking&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;The food is expensive&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;The food is cold&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;It tastes good&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;I like the drink&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;The dessert is tasty&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;I don't like the services&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;It is too expensive&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Jan 2017 01:56:31 GMT</pubDate>
    <dc:creator>neelima</dc:creator>
    <dc:date>2017-01-26T01:56:31Z</dc:date>
    <item>
      <title>Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327614#M73087</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data as below and need&amp;nbsp;to find out which CUSTOMER has given a "5" score and then immediately followed with a missing score. can you please suggest how to achive this in Data step.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;SCORE&lt;/TD&gt;&lt;TD&gt;COMMENT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;I like the food&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;The service is very bad&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;The is no parking&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;The food is expensive&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;The food is cold&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;It tastes good&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;I like the drink&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;The dessert is tasty&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;I don't like the services&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;It is too expensive&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 01:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327614#M73087</guid>
      <dc:creator>neelima</dc:creator>
      <dc:date>2017-01-26T01:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327616#M73088</link>
      <description>&lt;P&gt;One way to go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm='|';
  input customer :$8.  SCORE :best32.  COMMENT $40.;
  datalines;
A|4|I like the food
A|2|The service is very bad
A|3|The is no parking
A|5|The food is expensive
B|2|The food is cold
B|5|It tastes good
B|.| 
B|3|I like the drink
C|4|The dessert is tasty
C|2|I don't like the services
C|3|It is too expensive
;
run;

data want;
  set have;
  if lag(customer)=customer and lag(score)=5 and missing(score) then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327616#M73088</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-26T02:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327617#M73089</link>
      <description>&lt;P&gt;I'm not a big fan of the&amp;nbsp;&lt;EM&gt;lag&lt;/EM&gt; function, but this is a situation where it works well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
infile cards dsd dlm='09'x;   /* Separated by tabs, as in the posted data */
attrib c length=$ 1;
attrib score length=3;
attrib comment length=$ 30;
input c
      score
      comment;
cards;
A	4	I like the food
A	2	The service is very bad
A	3	The is no parking
A	5	The food is expensive
B	2	The food is cold
B	5	It tastes good
B	.	 
B	3	I like the drink
C	4	The dessert is tasty
C	2	I don't like the services
C	3	It is too expensive
;
run;

data score_plus_null;
set source;
if c = lag(c)                 /* If it's still the same customer */
 &amp;amp; missing(score)             /* if the current score is missing */
 &amp;amp; lag(score) = 5;            /* if the previous score is 5 */
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327617#M73089</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-26T02:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327620#M73090</link>
      <description>&lt;P&gt;Hi Pat,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327620#M73090</guid>
      <dc:creator>neelima</dc:creator>
      <dc:date>2017-01-26T02:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327622#M73091</link>
      <description>&lt;P&gt;Hi Pat,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also can you please help how to&amp;nbsp;find out which CUSTOMER has comment on "parking" AND "expensive" on same dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327622#M73091</guid>
      <dc:creator>neelima</dc:creator>
      <dc:date>2017-01-26T02:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327624#M73092</link>
      <description>&lt;P&gt;Here's one way of doing it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data target;
set source;
by c;
if first.c then
   count = 0;
if indexw(comment, 'expensive')
 | indexw(comment, 'parking') then
   count + 1;
if last.c;
if count = 2;
keep c;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327624#M73092</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-26T02:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327627#M73094</link>
      <description>&lt;P&gt;Hi Laurie,&lt;/P&gt;&lt;P&gt;It works. thanks a lot for your shift response.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327627#M73094</guid>
      <dc:creator>neelima</dc:creator>
      <dc:date>2017-01-26T02:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327629#M73096</link>
      <description>&lt;P&gt;Here you go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm='|';
  input customer :$8.  SCORE :best32.  COMMENT $40.;
  datalines;
A|4|I like the food
A|2|The service is very bad
A|5|The is no parking
A|.|The food is expensive
B|3|The food is cold
B|5|It tastes good
B|.| 
B|3|I like the drink
C|4|The dessert is tasty
C|2|I don't like the services
C|3|It is too expensive
;
run;

data want;
  set have;
  by customer notsorted;
  _lag_score=lag(score);
  retain score_flg expensive_flg parking_flg;
  if not first.customer and _lag_score=5 and missing(score) then score_flg=1;
  if findw(comment,'expensive',' ','i') then expensive_flg=1;
  if findw(comment,'parking',' ','i') then parking_flg=1;
  if last.customer then
    do;
      output;
      call missing(score_flg, expensive_flg, parking_flg);
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the future: Try to have a single question per thread. Start a new thread with new or additional questions; reference an existing thread if the question is related to it.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327629#M73096</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-26T02:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327630#M73097</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;What happens if &lt;EM&gt;expensive&lt;/EM&gt; and &lt;EM&gt;parking&lt;/EM&gt; are in the same comment, or if there are two comments with &lt;EM&gt;parking &lt;/EM&gt;but no &lt;EM&gt;expensive?&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327630#M73097</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-26T02:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327632#M73099</link>
      <description>&lt;P&gt;There's really no way of getting around that with (apparently) free-form text fields: it would require natural language parsing. If the responses however were from a finite unmodifiable list, then it would be quite straightforward but we'd need to know what the finite list contained. I always prefer to cope with codes, rather than text strings, for such a problem. But we don't always have that luxury, of course.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first problem: it'd work unmodified, but the first paragraph is important; the second would be a case of adding up the strings individually. Again, refer to first paragraph!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first rule of data analysis: know thy data…&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 03:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327632#M73099</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-26T03:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327636#M73101</link>
      <description>&lt;P&gt;Requirement&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;which CUSTOMER has comment on "parking" AND "expensive" on same dataset.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;What I've tried to point out to you is, that the code you've posted doesn't meet the requirements as posted by the OP.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're just counting per record if there is at least one occurrence of a word and though you would return a "requirement met" if there are only two occurrences of word&amp;nbsp;&lt;EM&gt;parking&lt;/EM&gt;. On the other hand you would miss the cases where &lt;EM&gt;parking&lt;/EM&gt; and &lt;EM&gt;expensive &lt;/EM&gt;both&amp;nbsp;exists in a single record (your "count" would be 1 instead of 2).&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 04:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327636#M73101</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-26T04:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327640#M73104</link>
      <description>&lt;P&gt;Yes. I almost completely&amp;nbsp;agree. But this brings up one of the main problem with the puzzles we are set here, and one of the main problems I have in my career (touched on by "Know Thy Data"). Without a solid amount of data to test problems on, it's really easy to make assumptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a perfect world, with&amp;nbsp;&lt;EM&gt;lots&lt;/EM&gt; of data, I would check the cardinality of the text field to check whether it was free-form text or not. If I could confirm that it was the case (very high cardinality), I would tailor my code to fit. With a small set of data, I made an assumption based on my understanding of the spec, and I would argue that I was correct, even if I wasn't right &amp;lt;grin&amp;gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that doesn't matter. I have (mostly silently) disagreed with some of the answers that people have given in the past, but the question setter has been happy so it is of no import. I think it is less likely that a single slanted interpretation of a specification is going to be accepted if there are extensive source data from which to formulate a solution. I blanch when I'm given test data which has been put together by a business analyst which may only have a hundred or a thousand observations in it. If it's a banking system, give me&amp;nbsp;&lt;EM&gt;all&lt;/EM&gt; the customers,&amp;nbsp;&lt;EM&gt;all&amp;nbsp;&lt;/EM&gt;the accounts and&amp;nbsp;&lt;EM&gt;all&amp;nbsp;&lt;/EM&gt;their transactions. It'll take me a wee bit longer to analyse it, but I&amp;nbsp;&lt;EM&gt;will&lt;/EM&gt;&amp;nbsp;eventually come up with a solution which is more likely to last.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 06:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-data-step-logic/m-p/327640#M73104</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-26T06:55:59Z</dc:date>
    </item>
  </channel>
</rss>

