/*** TIP 00393 ***/
/***
Example of Getting User Input Interactively
Author: Charles Patridge
Demonstration of Simple Use of using WINDOW statement to
solicit input from User and Process the input

Assumption is made you only have BASE SAS available

You should have your program window in MAXMIUM WINDOW size before
executing this.

This is a simple example of WINDOWS and has a couple of macros
embedded to display some data values - however, this is not a
realistic example as your data could easily fill up more than 1
screen to display such values -hence not very useable.

This was intended to show how to use Windows to gather INPUT.

You should read up on the Window Statement to get more info about
the parameters and how they would.
***/


/***
Example of Getting User Input Interactively
***/

Data _null_;
  window start
        #5 @26 'Welcome to the SAS System' color=red
        #7 @26 'This Program is for Demonstration' color=black
        #9 @26 'Press the Enter Key to Continue' color=blue
   ;
  display start;
  stop;
 run;

/*** end of simple display ***/

/***
 now demo a simple display and collect some input - data
***/

 data test;
  article = "Education";
  a = 4; /*** Adams   ***/
  b = 2; /*** Brown   ***/
  j = 5; /*** Johnson ***/
  s = 1; /*** Smith   ***/
  t = 0; /*** Thomas  ***/
  output;
  article = "Journals";
  a = 1; /*** Adams   ***/
  b = 2; /*** Brown   ***/
  j = 3; /*** Johnson ***/
  s = 4; /*** Smith   ***/
  t = 5; /*** Thomas  ***/
  output;
 run;

 data assign;
  set test end=final;
  window assign irow=1 rows=3 color=magenta
         #3 @10 'Article:' color=white +1 article color=white protect=yes +5 'Name:' +1 name $14. color=white
  ;
  window showtot irow=7 rows=13 color=cyan
         group=subtot
         #1 @5  'Article:'    color=white +1 article  color=pink
         #2 @10 'Adams has'   color=white +1 a
         #3 @10 'Brown has'   color=white +1 b
         #4 @10 'Johnson has' color=white +1 j
         #5 @10 'Smith has'   color=white +1 s
         #6 @10 'Thomas has'  color=white +1 t
         group=lastmsg
         #8 @10 'All Articles assigned. Press Enter to Stop Processing' color=red
  ;
   display showtot.subtot blank noinput;
   display assign blank ;
         if name='Adams'   then a+1;
    else if name='Brown'   then b+1;
    else if name='Johnson' then j+1;
    else if name='Smith'   then s+1;
    else if name='Thomas'  then t+1;

   display showtot.subtot blank noinput;
   if final then display showtot.lastmsg;
 run;

/*** Example of Getting User Input Interactively ***/ Data _null_; window start #5 @26 'Welcome to the SAS System' color=red #7 @26 'This Program is for Demonstration' color=black #9 @26 'Press the Enter Key to Continue' color=blue ; display start; stop; run; /*** end of simple display ***/ /*** now demo a simple display and collect some input - data ***/ data test; length name $14.; article = "Education"; name = "Adams" ; amt = 4; output; article = "Education"; name = "Brown" ; amt = 2; output; article = "Education"; name = "Johnson"; amt = 5; output; article = "Education"; name = "Smith" ; amt = 1; output; article = "Education"; name = "Thomas" ; amt = 0; output; run; data assign; set test end=final; window assign irow=3 rows=8 color=magenta #1 @10 'Article:' color=white +1 article color=white protect=yes #2 @10 'Name:' color=white +1 name $14. color=white protect=yes #3 @10 'Current Amount: ' color=white +1 amt color=white protect=yes #4 @10 'Enter New Amt: ' color=white +1 getamt color=white protect=no ; display assign blank ; if getamt ne . then do; window show irow=10 rows=10 color=cyan group=nochange #1 @5 'Article:' color=white +1 article color=white persist=yes protect=yes #2 @10 'Name: ' color=white +1 name color=white persist=yes #3 @10 'Amount was:' color=white +1 amt color=white persist=yes group=change #4 @10 'Amount now:' color=red +1 getamt color=red persist=yes ; display show.nochange blank noinput; display show.change noinput; amt = getamt; end; if getamt eq . then do; display show.nochange blank noinput; end; if final then do; window final irow=20 rows=10 color=cyan #1 @10 'All Articles assigned. Press Enter to Stop Processing' color=red ; display final blank; end; run;
/*** Example of Getting User Input Interactively Author: Charles Patridge Demonstration of Simple Use of using WINDOW statement to solicit input from User and Process the input Assumption is made you only have BASE SAS available You should have your program window in MAXMIUM WINDOW size before executing this. This is a simple example of WINDOWS and has a couple of macros embedded to display some data values - however, this is not a realistic example as your data could easily fill up more than 1 screen to display such values -hence not very useable. This was intended to show how to use Windows to gather INPUT. You should read up on the Window Statement to get more info about the parameters and how they would. ***/ /*** Simple Display Window ***/ Data _null_; window start color=yellow #5 @26 'Welcome to the SAS System' color=red #7 @26 'This Program is for Demonstration' color=black #9 @26 'Press the Enter Key to Continue' color=blue ; display start; stop; run; /*** end of simple display ***/ /*** now demo a simple display and collect some input - data ***/ /*** create some test data ***/ data test; length name $14.; article = "Education"; name = "Adams" ; amt = 4; output; article = "Education"; name = "Brown" ; amt = 2; output; article = "Education"; name = "Johnson"; amt = 5; output; article = "Education"; name = "Smith" ; amt = 1; output; article = "Education"; name = "Thomas" ; amt = 0; output; run; /*** create macro emptyyn to get number of records in SAS dataset ***/ %MACRO EMPTYYN(DSNAME); %global numobs; DATA _NULL_; IF "&DSNAME " = " " THEN CALL SYMPUT('DSNAME','_LAST_'); RUN; DATA _NULL_; IF 0 THEN SET &DSNAME NOBS=NUMOBS; CALL SYMPUT('NUMOBS' ,PUT(NUMOBS , BEST.)); STOP; RUN; %MEND EMPTYYN; %emptyyn( test ); /*** get number of records in test ***/ %let numrec = &numobs; /*** macro var created by emptyyn ***/ /*** create macro to display data values for SAS ARRAY var ***/ %macro showvalues( windowname=dummy, irow=20, rows=20, color=yellow, sasvara=names, sasvarb=, blank=blank, input=noinput); window &windowname irow=&irow rows=&rows color=&color %if &sasvarb eq %then %do; %do _K_ = 1 %to &numrec; #&_K_ @10 &sasvara(&_K_) %end; %end; %if &sasvarb ne %then %do; %do _K_ = 1 %to &numrec; #&_K_ @10 &sasvara(&_K_) +5 &sasvarb(&_K_) %end; %end; ; display &windowname &blank &input; %mend showvalues; %macro prompt; /*** Now Prompt User for What Names to Update ***/ data getrequest (keep=getname); array names(&numrec) $14; /*** creat an array with same number of elements as there are records in test ***/ i=0; do until (eof1); /*** load the array with names from test ***/ set test end=eof1; i=i+1; names(i)= upcase(name); end; length getname $14.; startover: ; window getrequest irow=3 rows=7 color=green #1 @10 "Please Enter Name of Person you wish to update" color=white protect=yes #2 @10 "Name ? " color=white +1 getname color=white protect=no #3 @10 "Enter _STOP_ if you wish to Terminate" color=white ; %showvalues( windowname=shownames, irow=20, rows=20, color=yellow, sasvara=names, sasvarb=, blank=, input=noinput); display getrequest blank; window input irow=10 rows=7 color=red group=good #1 @10 "OK - Got It!" color=white persist=yes group=bad #1 @10 "The Name you Entered does not exist!" color=white #2 @10 "Try Again !" color=white ; count = 0; do i = 1 to dim(names); if upcase(getname) = names(i) then do; count + 1; output; display input.good blank noinput; end; end; if upcase(getname) eq '_STOP_' then stop; /*** no more input ***/ /*** input was bad - does not agree with any names in dataset ***/ /*** have user start over ***/ if count = 0 then do; display input.bad blank noinput; count=0; goto startover; end; /*** start over - if user needs to quit have them type in "_STOP_" ***/ goto startover; run; %mend prompt; /*** prompt user for inputs ***/ %prompt; /*** determine how many records selected in update ***/ %emptyyn( getrequest ); %let numupd = &numobs ; %macro checkinput; %if 0 eq &numobs %then %do; Data _null_; window noupdates irow=20 rows=20 color=yellow #7 @26 'Nothing to Process' color=black #9 @26 'Press the Enter Key to Terminate' color=blue ; display noupdates; stop; run; %end; %mend checkinput; /*** if there are no records for updating - tell user ***/ %checkinput; /*** sort user input and eliminate duplicates, if any ***/ proc sort data=getrequest out=getrequest nodupkey; by getname; run; /*** get user's input to select what records need to be updated ***/ proc sql; create table update as select * from test as t, getrequest as g where g.getname eq t.name; quit; /*** if UPDATE is emptyyn the following code will not execute ***/ data assign (drop=getamt); set update (drop=getname) end=final; window assign irow=3 rows=8 color=magenta #1 @10 'Article:' color=white +1 article color=white protect=yes #2 @10 'Name:' color=white +1 name $14. color=white protect=yes #3 @10 'Current Amount: ' color=white +1 amt color=white protect=yes #4 @10 'Enter New Amt: ' color=white +1 getamt color=white protect=no ; display assign blank ; if getamt ne . then do; window show irow=10 rows=10 color=cyan group=nochange #1 @5 'Article:' color=white +1 article color=white persist=yes protect=yes #2 @10 'Name: ' color=white +1 name color=white persist=yes #3 @10 'Amount was:' color=white +1 amt color=white persist=yes group=change #4 @10 'Amount now:' color=red +1 getamt color=red persist=yes ; display show.nochange blank noinput; display show.change noinput; amt = getamt; end; if getamt eq . then do; display show.nochange blank noinput; end; if final then do; window final irow=20 rows=10 color=cyan #1 @10 'Last Record Updated. Press Enter to Stop Processing' color=red ; display final blank; end; run; /*** get users updates and sort ***/ proc sort data=assign out=assign; by name; run; proc sort data=test out=test ; by name; run; /*** now update TEST with User updates ***/ data test; merge test (in=t) assign (in=a); by name; run; %macro showresults; %if &numupd ne 0 %then %do; data display; array names(&numrec) $14; /*** creat an array with same number of elements as there are records in test ***/ array amts(&numrec) ; i=0; do until (eof1); /*** load the array with names and amt from test ***/ set test end=eof1; i=i+1; names(i)= name; amts(i) = amt; end; %showvalues( windowname=shownames, irow=20, rows=10, color=yellow, sasvara=names, sasvarb=amts, blank= , input=noinput); window stop irow=30 rows=15 color=yellow #7 @26 'End of Updates' color=black #9 @26 'Press the Enter Key to Terminate' color=blue ; display stop; stop; run; %end; %mend showresults; /*** show user updates so they can be verified, if any updates requested ***/ %showresults; /*** tell use end of demo ***/ Data _null_; window end irow=20 rows=20 color=yellow #7 @26 'End of Demonstration' color=black #9 @26 'Press the Enter Key to Terminate' color=blue ; display end; stop; run; *** endsas; /*** end of demonstration ***/ /*** end of tip 00393 ***/