/***
      Now I will show you how to eliminate using such
      IF...THEN...ELSE statements

      and replace them with ONE statement

      Making it easier to read and maintain your SAS program

      Let's Begin, Shall we ?
 ***/

 /*** First Create the Formats needed to group the States ***/
 /*** by a user defined Region                            ***/
 /*** these are for demonstration purposes only           ***/
 /*** MUCH EASIER TO READ, Right ???                      ***/

 Proc Format;
      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;

 /*** Will use the SAS Salary/Rate Survey Data to demonstrate ***/
 /*** Select only Full Time Employees ***/

 Data Select;
  set sasuser.SASALARY;
  if "FULL TIME EMPLOYEE" = upcase( empltype );
  state = zipstate ( substr( left( zipcode ), 1, 5 ) );

  /*** Now based upon the STATE code obtained from the
       ZIPSTATE function, we need to group the states
       according to a specified REGION that is user
       defined.
  ***/


 /*** DELETE THESE IF...THEN...ELSE Statements ***/
 /*** GROUP state codes by user defined REGION
      by the use of IF...THEN...ELSE statements ***/

     if state in ('CT','MA','RI','VT','NH','ME')
        then region = "NE"; /*** North East    ***/
else if state in ('NY','NJ','PA','DE','MD','DC','VA','WV')
        then region = "MA"; /*** Mid Atlantic  ***/
else if state in ('SC','NC','GA','AL','FL')
        then region = "SE"; /*** South East    ***/
else if state in ('OH','TN','KY','IL','IN','MI','WI')
        then region = "CN"; /*** Central North ***/
else if state in ('LA','MS','MO','TX','AR','OK','KS')
        then region = "CS"; /*** Central South ***/
else if state in ('IA','NE','SD','ND','MN','WS')
        then region = "MN"; /*** Mid West      ***/
else if state in ('WY','MT','ID','OR','WA')
        then region = "NW"; /*** North West    ***/
else if state in ('CA','NV','UT','CO','NM','AZ')
        then region = "SW"; /*** South West    ***/


 /*** And Replace them with a Single PUT Function using our
      user defined FORMAT - $REGNFMT ***/

 region = put( state, $regnfmt. );


 /*** Now select only those states in the North East ***/

 if region = 'NE';

 run;

 /*** MUCH SIMPLER TO READ and MAINTAIN, RIGHT ???    ***/

 /*** 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 ***/
 Title1 "New England - Statistics";
 Title2 "Minimum, Average and Maximum SAS Salaries";
 Proc Print data=stats ;
 By state;
 Id state;
 Var count minimum average maximum;
 Format  minimum average maximum dollar10.0;
 run;
 /*** end of program - sas_video_02b ***/