/**********************************************************************/

   /* The following OPTIONS and TITLE statements are used        */
   /* with all examples from this article that do not explicitly */
   /* contain other settings:                                    */

options nodate nonumber nolabel ls=64 ps=90;
title;


/**********************************************************************/


   /* The following SAS data set, SASUSER.HOUSES, is used to     */
   /* supply the data for most examples from this article:       */

STYLE    SQFEET BEDROOMS BATHS STREET                  PRICE
RANCH     1250      2     1.0  Sheppard Avenue       $64,000   
SPLIT     1190      1     1.0  Rand Street           $65,850   
CONDO     1400      2     1.5  Market Street         $80,050   
TWOSTORY  1810      4     3.0  Garris Street        $107,250   
RANCH     1500      3     3.0  Kemble Avenue         $86,650   
SPLIT     1615      4     3.0  West Drive            $94,450   
SPLIT     1305      3     1.5  Graham Avenue         $73,650   
CONDO     1390      3     2.5  Hampshire Avenue      $79,350   
TWOSTORY  1040      2     1.0  Sanders Road          $55,850   
CONDO     2105      4     2.5  Jeans Avenue         $127,150   
RANCH     1535      3     3.0  State Highway         $89,100   
TWOSTORY  1240      2     1.0  Fairbanks Circle      $69,250   
RANCH      720      1     1.0  Nicholson Drive       $34,550   
TWOSTORY  1745      4     2.5  Highland Road        $102,950   
CONDO     1860      2     2.0  Arcata Avenue        $110,700


/**********************************************************************/


data sample;
   input x $1.;
   cards;
1
a
A
z
Z
\
;

   /* OUTPUT 1a-1b                                               */
proc freq;
   tables x / nopercent nocum;
run;


/**********************************************************************/


proc sort data=sasuser.houses out=houses;
   by style;

   /* OUTPUT 2                                                   */
proc freq data=houses;
   by style;
   tables bedrooms / nopercent;
run;


/**********************************************************************/


   /* OUTPUT 3                                                   */
proc means data=sasuser.houses nway mean;
   class style;
   var sqfeet;
run;


/**********************************************************************/


   /* OUTPUT 4                                                   */
proc tabulate data=sasuser.houses format=3. noseps
              order=freq;
   class style bedrooms;
   table style*bedrooms, n / rts=23;
run;


/**********************************************************************/


   /* OUTPUT 5                                                   */
proc tabulate data=sasuser.houses format=3. noseps
              order=freq;
   class style bedrooms;
   table style*bedrooms, n / rts=23 printmiss;
run;


/**********************************************************************/


   /* OUTPUT 6                                                   */
proc report data=sasuser.houses nowd headskip;
   column bedrooms;
   define bedrooms / group format=numf. order=internal;
run;


/**********************************************************************/


data sample;
   length dept $ 5;
   input dept id;
   cards;
PET   100
PET   110
PET   120
PET   199
PLANT 200
PLANT 210
PLANT 220
PLANT 299
;

proc format;
   value idfmt
         100='CAT'    110='DOG' 120='FISH' 199='OTHER'
         200='CACTUS' 210='IVY' 220='FERN' 299='OTHER';

   /* OUTPUT 7                                                   */
proc tabulate data=sample noseps;
   class dept id;
   table dept*id, n;
   format id idfmt.;
run;


/**********************************************************************/


proc format;
   value bedfmt 1='ONE' 2='TWO' other='OTHER';

data houses;
   set sasuser.houses end=last;
   output;
   if last then do;
      bedrooms=.;
      output;
   end;
   format bedrooms bedfmt.;

   /* OUTPUT 8a                                                  */
proc print data=houses;
   title "WORK.HOUSES";
   var bedrooms;
   format bedrooms;

   /* OUTPUT 8b                                                  */
proc freq data=houses;
   title1 "PROC FREQ";
   title2 "Without MISSING Specified";
   tables bedrooms / nocum nopercent;
run;

   /* OUTPUT 8c                                                  */
proc report data=houses nowd headline;
   title1 "PROC REPORT";
   title2 "Without MISSING Specified";
   column bedrooms n;
   define bedrooms / group width=8;
run;


/**********************************************************************/


   /* OUTPUT 9a                                                  */
proc freq data=houses;
   title1 "PROC FREQ";
   title2 "With MISSING Specified";
   tables bedrooms / nocum nopercent missing ;
run;

   /* OUTPUT 9b                                                  */
proc report data=houses nowd headline missing;
   title1 "PROC REPORT";
   title2 "With MISSING Specified";
   column bedrooms n;
   define bedrooms / group width=8;
run;


/**********************************************************************/


options formdlim=' ';

proc sort data=sasuser.houses out=houses;
   by bedrooms;

proc format;
   value numf 3='GROUP A' 1,2,4='GROUP B';

   /* OUTPUT 10                                                  */
proc report data=houses nowd headskip;
   by bedrooms;
   format bedrooms numf.;
   column price;
run;


/**********************************************************************/


proc format;
   value numf 1='ONE' 2='TWO' 3='THREE' 4='FOUR';

   /* OUTPUT 11                                                  */
proc report data=sasuser.houses nowd headskip;
   column bedrooms;
   define bedrooms / group format=numf8. order=internal;
run;


/**********************************************************************/


proc format;
   value numf 1='ONE' 2='TWO' 3='THREE' 4='FOUR';

   /* OUTPUT 12                                                  */
proc freq data=sasuser.houses order=formatted;
   tables bedrooms / nopercent;
   format bedrooms numf.;
run;


/**********************************************************************/


   /* OUTPUT 13a                                                 */
proc report data=sasuser.houses nowd headskip;
   title1 "ORDER=FORMATTED";
   title2 "(default)";
   title4 "FORMAT=BEST9.";
   title5 "(default)";
   column baths;
   define baths / group width=9;

   /* OUTPUT 13b                                                 */
proc report data=sasuser.houses nowd headskip;
   title1 "ORDER=FORMATTED";
   title2 "(default)";
   title4 "FORMAT=3.1";
   title5 "(specified)";
   column baths;
   define baths / group width=9 format=3.1;

   /* OUTPUT 13c                                                 */
proc report data=sasuser.houses nowd headskip;
   title1 "ORDER =INTERNAL";
   title2 "(specified)";
   title4 "FORMAT=BEST9.";
   title5 "(default)";
   column baths;
   define baths / group width=9 order=internal;
run;


/**********************************************************************/


   /* OUTPUT 14                                                  */
proc tabulate data=sasuser.houses order=data 
              format=3. noseps;
   class style;
   table style, n;
run;


/**********************************************************************/
 

   /* OUTPUT 15                                                  */
proc tabulate data=sasuser.houses order=data
              format=3. noseps;
   class style bedrooms;
   table style*bedrooms, n;
run;


/**********************************************************************/
 

proc format;
   value bedfmt 1='ONE' 2='TWO' 3='THREE' 4='FOUR';

   /* OUTPUT 16a                                                 */
proc tabulate data=sasuser.houses
              order=freq noseps format=3.;
   title1 "PROC TABULATE";
   title2 "Without Format";
   class bedrooms;
   table bedrooms, n;

   /* OUTPUT 16b                                                 */
proc freq data=sasuser.houses order=freq;
   title1 "PROC FREQ";
   title2 "Without Format";
   tables bedrooms / nocum nopercent;

   /* OUTPUT 16c                                                 */
 proc report data=sasuser.houses nowd headline;
   title1 "PROC REPORT";
   title2 "Without Format";
   title3 "Without DESCENDING";
   column bedrooms n;
   define bedrooms / group order=freq;

   /* OUTPUT 16d                                                 */
proc report data=sasuser.houses nowd headline;
   title1 "PROC REPORT";
   title2 "Without Format";
   title3 "With DESCENDING";
   column bedrooms n;
   define bedrooms / group order=freq descending;

   /* OUTPUT 16e                                                 */
proc tabulate data=sasuser.houses
              order=freq noseps format=3.;
   title1 "PROC TABULATE";
   title2 "With Format";
   class bedrooms;
   table bedrooms, n;
   format bedrooms bedfmt.;

   /* OUTPUT 16f                                                 */
proc freq data=sasuser.houses order=freq;
   title1 "PROC FREQ";
   title2 "With Format";
   tables bedrooms / nocum nopercent;
   format bedrooms bedfmt.;

   /* OUTPUT 16g                                                 */
proc report data=sasuser.houses nowd headline;
   title1 "PROC REPORT";
   title2 "With Format";
   title3 "Without DESCENDING";
   column bedrooms n;
   define bedrooms / group order=freq format=bedfmt8.;

   /* OUTPUT 16h                                                 */
proc report data=sasuser.houses nowd headline;
   title1 "PROC REPORT";
   title2 "With Format";
   title3 "With DESCENDING";
   column bedrooms n;
   define bedrooms / group order=freq
                           format=bedfmt8. descending;
run;


/**********************************************************************/
 

proc tabulate data=sasuser.houses
              order=freq format=3. noseps;
   class baths;
   table baths, n;
run;


/**********************************************************************/
 

proc tabulate data=sasuser.houses
   order=freq format=3. noseps;
   class baths bedrooms;
   table bedrooms*baths, n;
run;


/**********************************************************************/