/*** TIP 00396 ***/

/*** Simple Example 

Author: Charles Patridge

Getting User Input Interactively using %WINDOWS - assuming you only
have BASE SAS and no other SAS Products
***/

%macro userinput;

%global _STARTDATE_ _NAME_ _FIXDATE_;

/*** Create A Label to Start Over if needed ***/
%_beginning_:;
/*** Create WELCOME Screen and get Input ***/
%Window WELCOME color=blue
        rows =30 columns=80
        #5  @28 'Welcome to a Windows Demonstration' attr=highlight color=white
        #7  @15 "You are executing Release &sysver on &sysday, &sysdate.." color=white

        #9  @15 'Enter your Name: ' color=white
        _NAME_ 20 DISPLAY=YES REQUIRED=YES ATTR=UNDERLINE color=cyan

        #10 @15 'Enter Start Date You to Run Reports for: (MM/YYYY) ' color=white
        _STARTDATE_ 7  Display=YES REQUIRED=YES ATTR=UNDERLINE color=cyan

        #12 @29 'Press Enter to continue.' color=white
;

%let _name_      = ;      /*** default value of blanks ***
%let _startdate_ = 05/2003; /*** default value of May 2003 ***/

%Display WELCOME BELL;

/*** Verify User Input ***/
%Window VERIFY color=blue
        rows =30 columns=80

        #9  @15 'Is this your Correct Name?: (Y/N) ' color=white
        _NAME_      20 DISPLAY=YES PROTECT=YES  ATTR=UNDERLINE color=white
        ' '
        _vNAME_      1 DISPLAY=YES REQUIRED=YES ATTR=UNDERLINE color=cyan

        #10 @15 'Is this Correct Start Date to Run Reports for: (MM/YY) ' color=white
        _STARTDATE_  7  DISPLAY=YES PROTECT=YES  ATTR=UNDERLINE color=white
        ' '
        _vSTARTDATE_ 1  Display=YES REQUIRED=YES ATTR=UNDERLINE color=cyan

        #12 @29 'Press Enter to continue.' color=white
;

%Display verify bell;

%if %upcase(&_vNAME_)      ne Y %then %goto _beginning_;
%if %upcase(&_vSTARTDATE_) ne Y %then %goto _beginning_;

%_continue_:;

/*** Now check Numeric User Input for Start Date ***/
data chkinput;
  name = "&_NAME_";
  tmpdate = "&_STARTDATE_";
  strtmth = input( substr(tmpdate,1,2), 2. );
  strtyr  = input( substr(tmpdate,4,4), 4. );
  strtdate = mdy( strtmth, 01, strtyr );
  format strtdate mmddyy8.;

  if strtdate ne . then flag="GOOD";
                   else flag="BAD ";

  call symput( 'FLAG', trim(flag));
run;

 %if &FLAG = BAD %then %do;
     /*** if bad START date then prompt user for a correction ***/
     %Window ERRORDATE color=RED
             rows =30 columns=80
             #10 @15 'Start Date to Run Reports IS BAD: (MM/YYYY) ' color=white
             _STARTDATE_  7  DISPLAY=YES PROTECT=YES  ATTR=UNDERLINE color=white
             ' '
             #11 @15 'Please Re-Enter: (MM/YYYY) '  color=white
             _FIXDATE_  7  Display=YES REQUIRED=YES ATTR=UNDERLINE color=cyan

             #12 @29 'Press Enter to continue.' color=white
     ;

     %Display ERRORDATE bell;

     %put "BAD _STARTDATE = &_STARTDATE_  has been changed to &_FIXDATE_";
     %let _STARTDATE_ = &_FIXDATE_;  /*** correct date field ***/
     %goto _continue_;  /*** now check to be sure this is OK ***/
 %end;
run;

%mend userinput;


/*** needed to create macro program in order to use the %if statements ***/
/***  to check user input, for bad dates, etc etc ***/

%userinput;

/*** end of tip 00396 ***/