<?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: Macros -- %do &amp;amp; print ; Output procedure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macros-do-amp-print-Output-procedure/m-p/423813#M280992</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The exercises in the e-learning classes have the solution provided to you. Just click the Show Solution button at the bottom of the screen and you should see the solution inside the code that is showing on a blue background, as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="topx_macro_solution.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17545i530BB1D5DDD249CC/image-size/large?v=v2&amp;amp;px=999" role="button" title="topx_macro_solution.png" alt="topx_macro_solution.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2017 00:46:45 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2017-12-28T00:46:45Z</dc:date>
    <item>
      <title>Macros -- %do &amp; print ; Output procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-do-amp-print-Output-procedure/m-p/423809#M280991</link>
      <description>&lt;P&gt;&lt;STRONG&gt;This question is from SAS Macro Language 1;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question :&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Reminder&lt;/STRONG&gt;: Make sure you've&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A&gt;defined the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Orion&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;library&lt;/A&gt;.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Copy and paste the following macro into the editor. This macro creates a data set named&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Customer_Freq&lt;/STRONG&gt;, which summarizes the variable&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Total_Retail_Price&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;by&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Customer_ID&lt;/STRONG&gt;. The data is sorted in descending order by the value of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Sum&lt;/STRONG&gt;. The call SYMPUTX routine creates a series of variables named&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Top1&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;through&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Top&lt;EM&gt;x&lt;/EM&gt;&lt;/STRONG&gt;, where&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;x&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is the value of the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;parameter.&lt;PRE&gt;title;
footnote;
%macro tops(obs=3);
   proc means data=orion.order_fact sum nway noprint;
      var total_retail_price;
      class customer_ID;
      output out=customer_freq sum=sum;
   run;

   proc sort data=customer_freq;
      by descending sum;
   run;

   data _null_;
      set customer_freq(obs=&amp;amp;obs);
      call symputx('top'||left(_n_), Customer_ID);
   run;
%mend tops;&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;Modify the macro to print a list of the top x customers from the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;orion.customer_dim&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;data set. Display the variables&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Customer_ID&lt;/STRONG&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Customer_Name&lt;/STRONG&gt;, and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Customer_Type&lt;/STRONG&gt;. Use a macro loop to dynamically generate values for the WHERE statement based on the macro variables Top1 through Top&lt;EM&gt;x&lt;/EM&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;Call the macro with a null parameter value and view the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A&gt;results&lt;/A&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;title;&lt;BR /&gt;footnote;&lt;BR /&gt;%macro tops( obs=3);&lt;BR /&gt;proc means data=orion.order_fact sum nway noprint;&lt;BR /&gt;var total_retail_price;&lt;BR /&gt;class customer_ID;&lt;BR /&gt;output out=customer_freq sum=sum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=customer_freq;&lt;BR /&gt;by descending sum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set customer_freq(obs=&amp;amp;obs) ;&lt;BR /&gt;call symputx('top'||left(_n_), Customer_ID);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%do i = 1 %to &amp;amp;obs ;&lt;BR /&gt;proc print data = orion.customer_dim;&lt;BR /&gt;where Customer_ID = &amp;amp;&amp;amp;top&amp;amp;i ;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%end ;&lt;/P&gt;&lt;P&gt;%macro tops( obs=3);&lt;BR /&gt;proc means data=orion.order_fact sum nway noprint;&lt;BR /&gt;var total_retail_price;&lt;BR /&gt;class customer_ID;&lt;BR /&gt;output out=customer_freq sum=sum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=customer_freq;&lt;BR /&gt;by descending sum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set customer_freq(obs=&amp;amp;obs) ;&lt;BR /&gt;call symputx('top'||left(_n_), Customer_ID);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%do i = 1 %to &amp;amp;obs ;&lt;BR /&gt;proc print data = orion.customer_dim;&lt;BR /&gt;where Customer_ID = &amp;amp;&amp;amp;top&amp;amp;i ;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%end ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend tops;&lt;/P&gt;&lt;P&gt;%tops();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output is in a different format. Can someone help me to get the output in this format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="1" cellpadding="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Top 3 Customers&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Customer_ID Customer_Name Customer_Type &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;Karen Ballinger&lt;/TD&gt;&lt;TD&gt;Orion Club members high activity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;Ulrich Heyde&lt;/TD&gt;&lt;TD&gt;Internet/Catalog Customers&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;45&lt;/TD&gt;&lt;TD&gt;Dianne Patchin&lt;/TD&gt;&lt;TD&gt;Orion Club Gold members low activity&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Dec 2017 23:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-do-amp-print-Output-procedure/m-p/423809#M280991</guid>
      <dc:creator>chitturiratna</dc:creator>
      <dc:date>2017-12-27T23:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macros -- %do &amp; print ; Output procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-do-amp-print-Output-procedure/m-p/423813#M280992</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The exercises in the e-learning classes have the solution provided to you. Just click the Show Solution button at the bottom of the screen and you should see the solution inside the code that is showing on a blue background, as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="topx_macro_solution.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17545i530BB1D5DDD249CC/image-size/large?v=v2&amp;amp;px=999" role="button" title="topx_macro_solution.png" alt="topx_macro_solution.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 00:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-do-amp-print-Output-procedure/m-p/423813#M280992</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-12-28T00:46:45Z</dc:date>
    </item>
  </channel>
</rss>

