/* This file contains the portable SAS code that is used
   in the article 'Submitting Dynamic Code with the PMENU
   Procedure." in OBSERVATIONS. 

   Note that the screens may look different on your
   screen. The appearance depends on the operating system you are
   using.

   To create some of the outputs shown, you must enter
   the value given in the article in the appropriate
   popup windows.

*/

/* Run the following DATA steps to create the USER.GRAINS data
   set for the subsequent examples. */

options ls=64;
libname user 'your-SAS-DATA-LIBRARY';
title;
data user.wheat;
   input market $10. high low last month $ year;
   grain='Wheat';
   cards;
Farmville  4.01 3.75 3.88 jul 93
Farmville  3.85 3.62 3.85 mar 93
Farmville  3.67 3.60 3.64 dec 93
Monticello 3.57 3.47 3.49 jul 93
Monticello 3.50 3.33 3.43 mar 93
Monticello 3.40 3.22 3.24 dec 93
Plainview  3.33 3.09 3.12 jul 93
Plainview  3.55 3.40 3.43 mar 93
Plainview  3.90 3.76 3.88 dec 93
Farmville  3.62 3.53 3.61 jul 94
Farmville  3.41 3.22 3.29 mar 94
Farmville  3.70 3.59 3.66 dec 94
Monticello 3.55 3.39 3.52 jul 94
Monticello 3.50 3.31 3.33 mar 94
Monticello 3.71 3.61 3.61 dec 94
Plainview  3.80 3.59 3.65 jul 94
Plainview  3.44 3.22 3.35 mar 94
Plainview  3.82 3.70 3.70 dec 94
;
data user.corn;
   input market $10. high low last month $ year;
   grain='Corn';
   cards;
Farmville   3.00 2.56 2.78 jul 93
Farmville   2.67 2.49 2.58 mar 93
Farmville   2.75 2.54 2.59 dec 93
Monticello  2.58 2.50 2.51 jul 93
Monticello  2.60 2.32 2.53 mar 93
Monticello  2.43 2.26 2.36 dec 93
Plainview   2.73 2.68 2.69 jul 93
Plainview   2.85 2.59 2.79 mar 93
Plainview   2.54 2.42 2.44 dec 93
Farmville   3.02 2.76 2.80 jul 94
Farmville   2.87 2.77 2.78 mar 94
Farmville   2.55 2.44 2.49 dec 94
Monticello  2.75 2.57 2.61 jul 94
Monticello  2.40 2.12 2.40 mar 94
Monticello  2.50 2.46 2.47 dec 94
Plainview   2.82 2.68 2.77 jul 94
Plainview   2.85 2.65 2.69 mar 94
Plainview   2.90 2.70 2.74 dec 94
;
data user.oats;
   input market $10. high low last month $ year;
   grain='Oats';
   cards;
Farmville   1.42 1.33 1.34 jul 93
Farmville   1.36 1.24 1.25 mar 93
Farmville   1.60 1.49 1.50 dec 93
Monticello  1.55 1.13 1.13 jul 93
Monticello  1.10 1.02 1.10 mar 93
Monticello  1.13 1.09 1.10 dec 93
Plainview   1.22 1.08 1.10 jul 93
Plainview   1.33 1.20 1.22 mar 93
Plainview   1.55 1.40 1.43 dec 93
Farmville   1.22 1.03 1.14 jul 94
Farmville   1.46 1.34 1.46 mar 94
Farmville   1.47 1.29 1.36 dec 94
Monticello  1.45 1.23 1.32 jul 94
Monticello  1.40 1.33 1.37 mar 94
Monticello  1.13 1.00 1.04 dec 94
Plainview   1.23 1.18 1.20 jul 94
Plainview   1.43 1.20 1.42 mar 94
Plainview   1.09 1.07 1.07 dec 94
;
data user.grains;
  set user.wheat user.corn user.oats;
run;


/* The following code creates a macro window
   like the window you see in Display 1. */

filename wheat  'your-external-filename';
filename corn   'your-external-filename';
filename oats   'your-external-filename';

/* This is the code stored in the file referenced
   by the fileref WHEAT. This PROC PRINT step
   creates the output you see in Display 2.  */

proc print data=user.grains noobs;
   title 'Report for Wheat';
   where grain='Wheat';
run;

/* This is the code stored in the file referenced
   by the fileref CORN:  */

proc print data=user.grains noobs;
   title 'Report for Corn';
   where grain='Corn';
run;

/* This is the code stored in the file referenced
   by the fileref OATS:  */

proc print data=user.grains noobs;
   title 'Report for Oats';
   where grain='Oats';
run;


dm 'pmenu on'; 

proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Wheat' selection=wheat;
      item 'Corn'  selection=corn;
      item 'Oats'  selection=oats;
      selection wheat 'end; include wheat;submit';
      selection corn  'end; include corn ;submit';
      selection oats  'end; include oats ;submit';
quit;

%window observe menu=user.menus.main columns=65
  #5 @18 'Please Choose a Report';
%display observe;


/* The following PROC PMENU step and %WINDOW statement
   create a window with menus like you see in
   Display 3. */

filename pickgr 'your-external-filename';
dm 'pmenu on';

proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Select Commodities'  dialog=threegr;
      dialog threegr 'end; include pickgr;change xxxx %1;submit';
      text #1 @7 'Select a Commodity';
     radiobox default=1;
        rbutton #3 @10 'Wheat';
        rbutton #4 @10 'Corn';
        rbutton #5 @10 'Oats';
quit;

%window observe menu=user.menus.main columns=65
   #5 @18 'Please Choose a Report';
%display observe;


/* This is the code stored in the file referenced by
   the fileref PICKGR. This code creates the output
   that you see in Display 4.  */

proc print data=user.grains noobs;
   title 'Commodities Report';
   where grain='xxxx';
run;


/* The following PROC PMENU step and PROC MEANS
   step enable you to create the output shown
   in Display 5. */

filename summary 'your-external-filename';
dm 'pmenu on';

proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Select Commodities'  dialog=threegr;
      dialog threegr 'end; include summary;
             change xxxx %1  all;submit';
      text #1 @7 'Select a Commodity';
      radiobox default=1;
         rbutton #3 @10 'Wheat';
         rbutton #4 @10 'Corn';
         rbutton #5 @10 'Oats';
quit;

%window observe menu=user.menus.main columns=65
   #5 @18 'Please Choose a Report';
%display observe;

/* This is the code stored in the file referenced by
   the fileref SUMMARY. */

proc means data=user.grains mean maxdec=2; 
   where grain='xxxx';                                                                                               
   class year;                                                                                                                  
   title 'Summary Data for xxxx for 1993 and 1994';
run;    



/* The following PROC PMENU step enables you to create the 
   window shown in Display 6. */


filename commrep 'your-external-filename';
dm 'pmenu on';

proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Select Commodities'  dialog=gmy;
      dialog gmy 'end;include commrep;change xxxx %1 all;
                  change yyyy %2 all; change zzzz %3 all;submit';
      text #1 @7 'Select a Commodity';
      radiobox default=1;
         rbutton #3  @10 'Wheat';
         rbutton #4  @10 'Corn';
         rbutton #5  @10 'Oats';
      text #7 @7 'Select a Market';
      radiobox default=1;
         rbutton #9  @10 'Farmville';
         rbutton #10 @10 'Monticello';
         rbutton #11 @10 'Plainview';
      text #13 @7 'Select a Year';
      radiobox default=1;
         rbutton #15 @10 '93';
         rbutton #16 @10 '94';
quit;

%window observe menu=user.menus.main columns=65
   #5 @18 'Please Choose a Report';
%display observe;

/* The following is the SAS code that produces the output shown
   in Display 7. It is stored in the file referenced by the
   fileref COMMREP: */

options formdlim=' ';
title 'Commodity Prices - xxxx';

proc print data=user.grains noobs;
   where lowcase(grain) =lowcase('xxxx') and
         lowcase(market)=lowcase('yyyy')and
                    year=zzzz;
run;

title 'Summary Information for xxxx';
proc means data=user.grains mean maxdec=2;
   where lowcase(grain) =lowcase('xxxx') and
         lowcase(market)=lowcase('yyyy')and
                    year=zzzz;
   class market year;
run;


/* The following program produces the same window,
   pull-down menus, and output as shown in 
   Displays 6 and 7: */


dm 'pmenu on';

proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Select Commodities'  dialog=gmy;
      dialog gmy "end;submit '%%choose(%1,%2,%3)';";
         text #1 @7 'Select a Commodity';
         radiobox default=1;
            rbutton #3  @10 'Wheat';
            rbutton #4  @10 'Corn';
            rbutton #5  @10 'Oats';
         text #7 @7 'Select a Market';
         radiobox default=1;
            rbutton #9  @10 'Farmville';
            rbutton #10 @10 'Monticello';
            rbutton #11 @10 'Plainview';
         text #13 @7 'Select a Year';
         radiobox default=1;
            rbutton #15 @10 '93';
            rbutton #16 @10 '94';
quit;

%macro choose(com,mkt,yr);
title "Commodity Prices - &com";
proc print data=user.grains noobs;
   where lowcase(grain) =lowcase("&com") and
         lowcase(market)=lowcase("&mkt")and
                   year =&yr;
run;

title "Summary Information for &com";
proc means data=user.grains mean maxdec=2;
   where lowcase(grain) =lowcase("&com") and
         lowcase(market)=lowcase("&mkt")and
                   year =&yr;
   class market year;
run;
%mend choose;

%window observe menu=user.menus.main columns=65
  #5 @18 'Please Choose a Report';
%display observe;

/*  The following program creates and displays the
    Display 8: */

dm 'pmenu on';
proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Select Commodities'  dialog=gmy;
   dialog gmy "end;submit '%%choose(%1,%2,%3,@1)';";
      text #1 @7 'Select a Commodity';
      radiobox default=1;
         rbutton #3  @10 'Wheat';
         rbutton #4  @10 'Corn';
         rbutton #5  @10 'Oats';
      text #7 @7 'Select a Market';
      radiobox default=1;
         rbutton #9  @10 'Farmville';
         rbutton #10 @10 'Monticello';
         rbutton #11 @10 'Plainview';
      text #13 @7 'Select a Year';
      radiobox default=1;
         rbutton #15 @10 '93';
         rbutton #16 @10 '94';
      text #18 @7 'Please Enter Secondary Title';
      text #20 @1 len=70;
quit;

%macro choose(com,mkt,yr,auxtitle);
title2 "Commodities Report - &com";
title3 "&auxtitle";
proc print data=grains;
   where lowcase(grain) =lowcase("&com") and
         lowcase(market)=lowcase("&mkt")and
                 year =&yr;
run;
proc means data=grains mean maxdec=2;
   where lowcase(grain) =lowcase("&com") and
         lowcase(market)=lowcase("&mkt")and
                 year =&yr;
   class market year;
run;
%mend choose;

%window observe menu=user.menus.main  columns=65
   #5 @18 'Please Choose a Report';
%display observe;

/* The following code produces the same popup window
   that you see in Display 8: */

dm 'pmenu on';
proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Select Commodities'  dialog=gmy;
   dialog gmy "end;%%let auxtitle=@1;
          submit '%%choose(%1,%2,%3)';";
      text #1 @7 'Select a Commodity';
      radiobox default=1;
         rbutton #3  @10 'Wheat';
         rbutton #4  @10 'Corn';
         rbutton #5  @10 'Oats';
      text #7 @7 'Select a Market';
      radiobox default=1;
         rbutton #9  @10 'Farmville';
         rbutton #10 @10 'Monticello';
         rbutton #11 @10 'Plainview';
      text #13 @7 'Select A Year';
      radiobox default=1;
         rbutton #15 @10 '93';
         rbutton #16 @10 '94';
      text #18 @7 'Please Enter Secondary Title';
      text #20 @1 len=70;
quit;

%macro choose(com,mkt,yr);
title2 "Commodities Report - &com";
title3 "&auxtitle";
proc print data=grains;
   where lowcase(grain) =lowcase("&com") and
         lowcase(market)=lowcase("&mkt")and
                 year =&yr;
run;
proc means data=grains mean maxdec=2;
   where lowcase(grain) =lowcase("&com") and
         lowcase(market)=lowcase("&mkt")and
                 year =&yr;
   class market year;
run;
%mend choose;

%window observe menu=user.menus.main columns=65
   #5 @18 'Please Choose a Report';
%display observe;


/* The following code creates Display 9, Display 10 and
   Display 11: */

dm 'pmenu on';
proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Subset Data'  dialog=gmy;
      dialog gmy "fsview user.grains(where=(high gt @1))";
         text #1 @7 'Specify Minimum Cutoff Point';
         text #3 @15 len=5;
quit;

%window observe menu=user.menus.main columns=65
   #5 @18 'Please Choose a Report';
%display observe;


/* The following code enables you to create the output
   shown in Display 12: */

dm 'pmenu on';
proc pmenu catalog=user.menus;
   menu main;
      item 'File' menu=file;
      item 'Reports' menu=reports;
   menu file;
      item 'End';
   menu reports;
      item 'Subset Data'  dialog=gmy;
      dialog gmy 'fsview user.grains(where=(%%subset(@1)))';
         text #1 @7 'Specify Minimum Cutoff Point';
         text #3 @15 len=5;
quit;

%macro subset(cutoff);
  high gt &cutoff or last gt &cutoff
%mend subset;

%window observe menu=user.menus.main columns=65
  #5 @18 'Please Choose a Report';
%display observe;