/***

On-Line SAS Training, Tips and Techniques using Audio/Video Technology.

Sample #1: OpenVMS on Alpha, running SAS Version 6.12

Show how to make an existing SAS program do more with the use of
Macros.  I will take a SAS program and generate reports
concerning the SAS Salary/Rate Survey found on WWW.SCONSIG.COM.

  A.  How many participants from New England.
  B.  What is Minimum, Average and High Salaries in New England.
  C.  Item B by state.

  D.  Then do the same for the Other Regions of USA

  Method Propose:  Make SAS Program into a Macro - Much Better

***/

 /*** Create Formats for Printing and Selection Purposes ***/
 /*** these are for demonstration purposes only          ***/

 Proc Format;
      Value $statfmt
                 " " = "Total";
      Value $regnfmt
                CT, MA, RI, VT, NH, ME = "NE" /*** New England  ***/
        NY, NJ, PA, DE, MD, DC, VA, WV = "MA" /*** Mid Altantic ***/
                    SC, NC, GA, AL, FL = "SE" /*** South East   ***/
            OH, TN, KY, IL, IN, MI, WI = "CN" /*** Central North***/
            LA, MS, MO, TX, AR, OK, KS = "CS" /*** Central South***/
                IA, NE, SD, ND, MN, WS = "MN" /*** Mid West ***/
                    WY, MT, ID, OR, WA = "NW" /*** North West ***/
                CA, NV, UT, CO, NM, AZ = "SW" /*** South West ***/
 run;


 options ls= 72 date center number pageno=1;
 %MACRO REGNRPT( REGION, TITLE );
 /*** Get, Select, and Filter Data ***/
 /*** create temp SAS dataset called Select ***/
 Data Select;
  /*** read permanent SAS dataset SASALARY from Library SASUSER ***/
  set sasuser.SASALARY;

  /*** Select Full Time Employees ***/
  if "FULL TIME EMPLOYEE" = upcase( empltype );

  /*** get state code  ***/
  state = zipstate ( substr( left( zipcode ), 1, 5 ) );

  /*** create Region code using a Format ***/
  region = put( state, $regnfmt.);

  /*** selection filter -  get NE only ***/
  if region = "®ION";
  Title1 "&TITLE";
 run;


 /*** Calculate Statistics using Proc Means ***/

 Proc Means data=Select;
 class state;
 var salary;
 output out=stats  n   (salary) = count
                   min (salary) = minimum
                   mean(salary) = average
                   max (salary) = maximum ;
 run;

 /*** Print Report ***/

 Title2 "Minimum, Average and Maximum SAS Salaries";
 Proc Print data=stats ;
 By state;
 Id state;
 Var count minimum average maximum;
 Format state $statfmt.  minimum average maximum dollar10.0;
 run;
 %MEND REGNRPT;

 %REGNRPT( NE, New England - Statistics );

 /*** end of program - sas_video_03 ***/