<?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 SAS ODS Query in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399008#M19452</link>
    <description>&lt;P&gt;May I know why the car2 report ‘Summary by model level’ not appear after the title, but start on the next page? Anyone can help? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA CAR;&lt;BR /&gt;SET SASHELP.CARS;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CAR1 AS SELECT DISTINCT&lt;BR /&gt;MAKE, SUM(INVOICE) AS INVOICE&lt;BR /&gt;FROM CAR WHERE MAKE EQ 'BMW'&lt;BR /&gt;GROUP BY MAKE&lt;BR /&gt;ORDER BY MAKE;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CAR2 AS SELECT DISTINCT&lt;BR /&gt;MAKE, MODEL, TYPE, ORIGIN, INVOICE&lt;BR /&gt;FROM CAR&lt;BR /&gt;ORDER BY MAKE, MODEL;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;DATA CAR2;&lt;BR /&gt;SET CAR2 CAR2 CAR2 CAR2 CAR2;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set CAR1 end=eof;&lt;BR /&gt;by MAKE;&lt;BR /&gt;/* On the first member of the BY-Group, create a new macro variable VARn */&lt;BR /&gt;/* and increment the counter FLAG. */&lt;BR /&gt;if first.MAKE then do;&lt;BR /&gt;flag+1;&lt;BR /&gt;call symput('var'||put(flag,8. -L),MAKE);&lt;BR /&gt;end;&lt;BR /&gt;/* On the last observation of the data set, create a macro variable to */&lt;BR /&gt;/* contain the final value of FLAG. */&lt;BR /&gt;if eof then call symput('tot',put(flag,8. -L));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Create a macro to generate the new data sets. Dynamically produce data set names */&lt;BR /&gt;/* on the DATA statement, using subsetting criteria to create the new data sets */&lt;BR /&gt;/* based upon the value of the BY variable. */&lt;/P&gt;&lt;P&gt;%macro groups(dsn,byvar);&lt;BR /&gt;%do i=1 %to &amp;amp;tot;&lt;BR /&gt;data "_&amp;amp;&amp;amp;var&amp;amp;i";&lt;BR /&gt;set &amp;amp;dsn;&lt;BR /&gt;if &amp;amp;byvar="&amp;amp;&amp;amp;var&amp;amp;i" then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct MAKE&lt;BR /&gt;into :orderedvars2 separated by ""&lt;BR /&gt;from CAR1&lt;BR /&gt;where MAKE eq "&amp;amp;&amp;amp;var&amp;amp;i";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;options nodate nonumber center;&lt;BR /&gt;ods escapechar="^";&lt;BR /&gt;title;&lt;BR /&gt;footnote;&lt;/P&gt;&lt;P&gt;/* Create a data set containing the desired title text */&lt;BR /&gt;data test;&lt;BR /&gt;text="^nCar Maker Summary Report - &amp;amp;orderedvars2^n&amp;amp;MTHWORD &amp;amp;YYYY";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%LET OUTPATH = D:\TEST\Incentive_ &amp;amp;YYYYMM-&amp;amp;orderedvars2..PDF;&lt;/P&gt;&lt;P&gt;ODS PDF FILE="&amp;amp;OUTPATH" compress=9 startpage=NO;&lt;/P&gt;&lt;P&gt;footnote1 j=c "Company Confidential";&lt;BR /&gt;*ods pdf text='^S={preimage="\\172.17.18.174\sas\_Common_\Images\saslogo.jpg"}';&lt;BR /&gt;ods pdf text="^20n";&lt;/P&gt;&lt;P&gt;/* Output the title text */&lt;BR /&gt;proc report data=test nowd noheader style(report)={rules=none frame=void}&lt;BR /&gt;style(column)={font_weight=bold font_size=20pt just=c};&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;options nocenter;&lt;BR /&gt;options orientation=landscape papersize=A3;&lt;BR /&gt;*options orientation=portrait papersize=A3;&lt;BR /&gt;ods pdf startpage=now;&lt;BR /&gt;ods pdf style=analysis;&lt;/P&gt;&lt;P&gt;TITLE "Car Maker -&amp;amp;Mthword &amp;amp;YYYY Summary";&lt;/P&gt;&lt;P&gt;ODS TEXT = "BRAND OVERALL SALES";&lt;BR /&gt;PROC PRINT DATA=CAR1(WHERE=(MAKE = "&amp;amp;&amp;amp;var&amp;amp;i")) NOOBS LABEL;&lt;BR /&gt;LABEL MAKE="MODEL"&lt;BR /&gt;INVOICE="PRICE";&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;ODS TEXT = " ";&lt;BR /&gt;ODS TEXT = " ";&lt;BR /&gt;ODS TEXT = "SUMMARY BY MODEL LEVEL";&lt;BR /&gt;&lt;BR /&gt;PROC REPORT DATA=CAR2(WHERE=(MAKE = "&amp;amp;&amp;amp;var&amp;amp;i"))style(header)=[background=tan] NOWINDOWS HEADLINE HEADSKIP;&lt;BR /&gt;COLUMNS MAKE MODEL TYPE ORIGIN INVOICE;&lt;BR /&gt;DEFINE MAKE /GROUP 'Car Brand';&lt;BR /&gt;DEFINE MODEL / DISPLAY 'Car Model';&lt;BR /&gt;DEFINE TYPE / DISPLAY 'Type';&lt;BR /&gt;DEFINE ORIGIN / DISPLAY 'Origin';&lt;BR /&gt;DEFINE INVOICE / SUM 'Price' FORMAT=DOLLAR16.2;&lt;BR /&gt;COMPUTE BEFORE MAKE;&lt;/P&gt;&lt;P&gt;ENDCOMP;&lt;/P&gt;&lt;P&gt;RBREAK AFTER/ SUMMARIZE;&lt;/P&gt;&lt;P&gt;COMPUTE AFTER;&lt;BR /&gt;MAKE = "TOTAL";&lt;BR /&gt;ENDCOMP;&lt;/P&gt;&lt;P&gt;BREAK AFTER MAKE / SKIP SUMMARIZE DOL DUL;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;ODS PDF CLOSE;&lt;BR /&gt;ODS LISTING;&lt;BR /&gt;ODS LISTING CLOSE;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend groups;&lt;/P&gt;&lt;P&gt;options mprint symbolgen;&lt;BR /&gt;%groups(CAR1,MAKE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2017 03:05:46 GMT</pubDate>
    <dc:creator>scb</dc:creator>
    <dc:date>2017-09-27T03:05:46Z</dc:date>
    <item>
      <title>SAS ODS Query</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399008#M19452</link>
      <description>&lt;P&gt;May I know why the car2 report ‘Summary by model level’ not appear after the title, but start on the next page? Anyone can help? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA CAR;&lt;BR /&gt;SET SASHELP.CARS;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CAR1 AS SELECT DISTINCT&lt;BR /&gt;MAKE, SUM(INVOICE) AS INVOICE&lt;BR /&gt;FROM CAR WHERE MAKE EQ 'BMW'&lt;BR /&gt;GROUP BY MAKE&lt;BR /&gt;ORDER BY MAKE;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CAR2 AS SELECT DISTINCT&lt;BR /&gt;MAKE, MODEL, TYPE, ORIGIN, INVOICE&lt;BR /&gt;FROM CAR&lt;BR /&gt;ORDER BY MAKE, MODEL;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;DATA CAR2;&lt;BR /&gt;SET CAR2 CAR2 CAR2 CAR2 CAR2;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set CAR1 end=eof;&lt;BR /&gt;by MAKE;&lt;BR /&gt;/* On the first member of the BY-Group, create a new macro variable VARn */&lt;BR /&gt;/* and increment the counter FLAG. */&lt;BR /&gt;if first.MAKE then do;&lt;BR /&gt;flag+1;&lt;BR /&gt;call symput('var'||put(flag,8. -L),MAKE);&lt;BR /&gt;end;&lt;BR /&gt;/* On the last observation of the data set, create a macro variable to */&lt;BR /&gt;/* contain the final value of FLAG. */&lt;BR /&gt;if eof then call symput('tot',put(flag,8. -L));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Create a macro to generate the new data sets. Dynamically produce data set names */&lt;BR /&gt;/* on the DATA statement, using subsetting criteria to create the new data sets */&lt;BR /&gt;/* based upon the value of the BY variable. */&lt;/P&gt;&lt;P&gt;%macro groups(dsn,byvar);&lt;BR /&gt;%do i=1 %to &amp;amp;tot;&lt;BR /&gt;data "_&amp;amp;&amp;amp;var&amp;amp;i";&lt;BR /&gt;set &amp;amp;dsn;&lt;BR /&gt;if &amp;amp;byvar="&amp;amp;&amp;amp;var&amp;amp;i" then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct MAKE&lt;BR /&gt;into :orderedvars2 separated by ""&lt;BR /&gt;from CAR1&lt;BR /&gt;where MAKE eq "&amp;amp;&amp;amp;var&amp;amp;i";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;options nodate nonumber center;&lt;BR /&gt;ods escapechar="^";&lt;BR /&gt;title;&lt;BR /&gt;footnote;&lt;/P&gt;&lt;P&gt;/* Create a data set containing the desired title text */&lt;BR /&gt;data test;&lt;BR /&gt;text="^nCar Maker Summary Report - &amp;amp;orderedvars2^n&amp;amp;MTHWORD &amp;amp;YYYY";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%LET OUTPATH = D:\TEST\Incentive_ &amp;amp;YYYYMM-&amp;amp;orderedvars2..PDF;&lt;/P&gt;&lt;P&gt;ODS PDF FILE="&amp;amp;OUTPATH" compress=9 startpage=NO;&lt;/P&gt;&lt;P&gt;footnote1 j=c "Company Confidential";&lt;BR /&gt;*ods pdf text='^S={preimage="\\172.17.18.174\sas\_Common_\Images\saslogo.jpg"}';&lt;BR /&gt;ods pdf text="^20n";&lt;/P&gt;&lt;P&gt;/* Output the title text */&lt;BR /&gt;proc report data=test nowd noheader style(report)={rules=none frame=void}&lt;BR /&gt;style(column)={font_weight=bold font_size=20pt just=c};&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;options nocenter;&lt;BR /&gt;options orientation=landscape papersize=A3;&lt;BR /&gt;*options orientation=portrait papersize=A3;&lt;BR /&gt;ods pdf startpage=now;&lt;BR /&gt;ods pdf style=analysis;&lt;/P&gt;&lt;P&gt;TITLE "Car Maker -&amp;amp;Mthword &amp;amp;YYYY Summary";&lt;/P&gt;&lt;P&gt;ODS TEXT = "BRAND OVERALL SALES";&lt;BR /&gt;PROC PRINT DATA=CAR1(WHERE=(MAKE = "&amp;amp;&amp;amp;var&amp;amp;i")) NOOBS LABEL;&lt;BR /&gt;LABEL MAKE="MODEL"&lt;BR /&gt;INVOICE="PRICE";&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;ODS TEXT = " ";&lt;BR /&gt;ODS TEXT = " ";&lt;BR /&gt;ODS TEXT = "SUMMARY BY MODEL LEVEL";&lt;BR /&gt;&lt;BR /&gt;PROC REPORT DATA=CAR2(WHERE=(MAKE = "&amp;amp;&amp;amp;var&amp;amp;i"))style(header)=[background=tan] NOWINDOWS HEADLINE HEADSKIP;&lt;BR /&gt;COLUMNS MAKE MODEL TYPE ORIGIN INVOICE;&lt;BR /&gt;DEFINE MAKE /GROUP 'Car Brand';&lt;BR /&gt;DEFINE MODEL / DISPLAY 'Car Model';&lt;BR /&gt;DEFINE TYPE / DISPLAY 'Type';&lt;BR /&gt;DEFINE ORIGIN / DISPLAY 'Origin';&lt;BR /&gt;DEFINE INVOICE / SUM 'Price' FORMAT=DOLLAR16.2;&lt;BR /&gt;COMPUTE BEFORE MAKE;&lt;/P&gt;&lt;P&gt;ENDCOMP;&lt;/P&gt;&lt;P&gt;RBREAK AFTER/ SUMMARIZE;&lt;/P&gt;&lt;P&gt;COMPUTE AFTER;&lt;BR /&gt;MAKE = "TOTAL";&lt;BR /&gt;ENDCOMP;&lt;/P&gt;&lt;P&gt;BREAK AFTER MAKE / SKIP SUMMARIZE DOL DUL;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;ODS PDF CLOSE;&lt;BR /&gt;ODS LISTING;&lt;BR /&gt;ODS LISTING CLOSE;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend groups;&lt;/P&gt;&lt;P&gt;options mprint symbolgen;&lt;BR /&gt;%groups(CAR1,MAKE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 03:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399008#M19452</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2017-09-27T03:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS ODS Query</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399026#M19453</link>
      <description>&lt;P&gt;To increase your chances of being helped:&lt;/P&gt;
&lt;P&gt;1- Reduce your problem&lt;/P&gt;
&lt;P&gt;&amp;nbsp; No one is keen to run and analyse 100+ lines of badly formatted code that contains smileys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Your problen can probably be replicated in a couple dozen lines at most. That part of the work is yours.&lt;/P&gt;
&lt;P&gt;2- Format you code properly to make it legible. This is a habit that will help you too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Indentations are useful, &lt;SPAN&gt;align things.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;My personal preference is keywords in lower case and user words (variable names, etc) in upper case.&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Find something that you like and stick to it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3- Post code using the {i} or the "notepad" icon above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which of the following 2 steps is easier to read and debug?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
PROC REPORT DATA=CAR2(WHERE=(MAKE = "&amp;amp;&amp;amp;var&amp;amp;i"))style(header)=[background=tan] NOWINDOWS HEADLINE HEADSKIP;
COLUMNS MAKE MODEL TYPE ORIGIN INVOICE;
DEFINE MAKE /GROUP 'Car Brand';
DEFINE MODEL / DISPLAY 'Car Model';
DEFINE TYPE / DISPLAY 'Type';
DEFINE ORIGIN / DISPLAY 'Origin';
DEFINE INVOICE / SUM 'Price' FORMAT=DOLLAR16.2;
COMPUTE BEFORE MAKE;
ENDCOMP;
RBREAK AFTER/ SUMMARIZE;
COMPUTE AFTER;
MAKE = "TOTAL";
ENDCOMP;
BREAK AFTER MAKE / SKIP SUMMARIZE DOL DUL;
RUN;

proc report data=CAR2(where=(MAKE = "&amp;amp;&amp;amp;var&amp;amp;i")) 
            style(header)=[background=tan] 
            nowindows 
            headline 
            headskip;
  columns MAKE MODEL TYPE ORIGIN INVOICE;
  define MAKE    / group   'Car Brand' ;
  define MODEL   / display 'Car Model' ;
  define TYPE    / display 'Type'      ;
  define ORIGIN  / display 'Origin'    ;
  define INVOICE / sum     'Price'     format=dollar16.2;
  rbreak after / summarize;
  compute after;
    MAKE = "TOTAL";
  endcomp;
  break after MAKE / skip summarize dol dul;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Sep 2017 05:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399026#M19453</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-09-27T05:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS ODS Query</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399218#M19460</link>
      <description>&lt;P&gt;ODS Text creates a table of output and so with it following your proc print it comes after the print output. As a separate table it is controlled by the startpage setting in effect.&lt;/P&gt;
&lt;P&gt;If you want that text to follow the title before the proc print then use a title2 or title3 or title4 statement (before the run for proc print).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then clear it after the proc with&lt;/P&gt;
&lt;P&gt;title2;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 15:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-ODS-Query/m-p/399218#M19460</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-27T15:09:22Z</dc:date>
    </item>
  </channel>
</rss>

