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

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

Title: Sounds "IFFY" ???

Demonstrate one technique for making a SAS more efficient and easy
to maintain.

  When a SAS program has a series of "IF" statements, one should
  think about an easier way to code the logic so it is easy to
  maintain as well as more efficient to execute.

  Let's take a look at an example.
***/

 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.
  ***/

 /*** 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    ***/


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

 if region = 'NE';

 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 ***/
 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_02a ***/