<?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: Macro help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383456#M277012</link>
    <description>Hi Reeza,&lt;BR /&gt;I want to see if a macro is more efficient in getting the values for each customer and I want to learn macro with this simple dataset.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;M</description>
    <pubDate>Thu, 27 Jul 2017 19:31:55 GMT</pubDate>
    <dc:creator>Malathi13</dc:creator>
    <dc:date>2017-07-27T19:31:55Z</dc:date>
    <item>
      <title>Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383385#M277009</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a data (Feedback) with customer, score and comments variables and I want to write a macro&amp;nbsp;that will programmatically call &lt;STRONG&gt;%subset&lt;/STRONG&gt; for each &lt;STRONG&gt;customer&lt;/STRONG&gt; value in &lt;STRONG&gt;Feedback.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Feedback&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;CUSTOMER&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;SCORE&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;COMMENT&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;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t;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;D&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;I don't like the services&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;[additional rows not shown]&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro subset( cust=);&lt;/P&gt;&lt;P&gt;proc print data= feedback;&lt;/P&gt;&lt;P&gt;where customer = "&amp;amp;cust";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get the value for each customer using %subset? Since I don't know how many customers are there, is there a easy way to write a macro for n customers?&lt;/P&gt;&lt;P&gt;Also I want to write a program to find out which customer&amp;nbsp;has given a "5" score immediately followed by a missing score and&amp;nbsp;find out which customer&amp;nbsp;has commented on “parking” and “expensive” . Since there are addititional rows that are not shown writing a macro should help in finding all the customers who commented on parkig and expensive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate all the help from you all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 18:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383385#M277009</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-07-27T18:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383434#M277010</link>
      <description>&lt;P&gt;You don't need a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort your dataset&amp;nbsp;and print by customer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=feedback; by customer; run;

proc print data=feedback;
  by customer;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you may wish create each customer's report starting a new page,&lt;/P&gt;
&lt;P&gt;then add line to the print procedure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=feedback;
  by customer;
  pageby customer;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can even print summary by adding: &amp;nbsp;&lt;STRONG&gt;sumby customer;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 19:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383434#M277010</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-27T19:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383447#M277011</link>
      <description>&lt;P&gt;Why do you think you need a macro?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 19:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383447#M277011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-27T19:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383456#M277012</link>
      <description>Hi Reeza,&lt;BR /&gt;I want to see if a macro is more efficient in getting the values for each customer and I want to learn macro with this simple dataset.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;M</description>
      <pubDate>Thu, 27 Jul 2017 19:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383456#M277012</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-07-27T19:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383459#M277013</link>
      <description>&lt;P&gt;If you're trying to learn then I would suggest the following two posts on how to split data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Split_Data_into_Subsets" target="_blank"&gt;http://www.sascommunity.org/wiki/Split_Data_into_Subsets&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;http://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, if you have a process where you want to call a macro multiple times I recommend CALL EXECUTE instead of macro loops or multiple calls. The documentation has an example of a macro and calling it using call execute. In fact, I think it's pretty close to your requirements above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n1q1527d51eivsn1ob5hnz0yd1hx.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n1q1527d51eivsn1ob5hnz0yd1hx.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 19:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383459#M277013</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-27T19:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383471#M277014</link>
      <description>&lt;P&gt;Most of those questions don't sound like issues for macro coding.&lt;/P&gt;
&lt;P&gt;Now if you want to conditionally generate macro calls using data from your table it is probably going to be much easier doing that using a data step, whether the data step is part of macro or not.&lt;/P&gt;
&lt;P&gt;First let's turn your sample into an actual dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data feedback ;
  input CUSTOMER $ score comment $40. ;
cards;
A 3 The is no parking
A 5 The food is expensive
B . I like the food
C 5 It tastes good
C . . 
C 3 I like the drink
D 4 The dessert is tasty
D 2 I don't like the services
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And make a simple macro that takes one customer ID as input.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print_subset(cust);
proc print data= feedback;
  where customer = "&amp;amp;cust";
run;
%mend print_subset;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can generate macro calls from the data using a simple data step. &amp;nbsp;Use BY group processing to call it only once per customer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set feedback;
  by customer ;
  if first.customer;
  call execute(cats('%nrstr(%print_subset)(',customer,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The other questions are about data processing, not macro programming.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;which customer&amp;nbsp;has given a "5" score immediately followed by a missing score&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subset1;
  do until (last.customer);
    set feedback ;
    by customer ;
    if score=. and prev_score=5 then found=1;
    prev_score=score;
  end;
  if found;
  keep customer;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;find out which customer&amp;nbsp;has commented on “parking” and “expensive”&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subset2;
  merge feedback(in=in1 where=(lowcase(comment) like '%parking%'))
        feedback(in=in2 where=(lowcase(comment) like '%expens%'))
  ;
  by customer;
  if first.customer and in1 and in2;
  keep customer;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2017 19:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383471#M277014</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-27T19:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383484#M277015</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thank you so much for the perfect answers, I really appreciate your help and the time you invested in helping me in the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much again.&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 20:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-help/m-p/383484#M277015</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-07-27T20:22:32Z</dc:date>
    </item>
  </channel>
</rss>

