data vals;
   input year $ country $ item $;
   cards;
1990 country1 item1
1990 country1 item2
1990 country2 item3
1990 country3 item1
1990 country3 item4
1991 country1 item1
1991 country1 item5
1991 country4 item3
1992 country1 item1
1992 country2 item2
1992 country3 item1
1992 country4 item4
1992 country4 item5
 ;
run;

________________________________________________________________________

INIT:

      /* Map variables in the data set to SCL variables so  */
      /* CALL SET can be used.  Make a master list. Sort    */
      /* master data set by year and remove duplicates.     */
      /* Set a counter for years, loop through the TEMP     */
      /* dataset to make a list for each year and insert    */
      /* list into the master list.                         */
  length year country item $ 8;
  dsid=open('vals');
  call set(dsid);
  rc=sort(dsid,'year','/nodupkey out=temp');
  tempid=open('temp');
  call set(tempid);
  yearlist=makelist();
  cnt=0;
  do while(fetch(tempid)=0);
     cnt + 1;
     rc=insertl(yearlist,makelist(),-1,year);

        /* Subset the master data set by each year, sort by */
        /* COUNTRY, and remove duplicates.  Open the TEMP2  */
        /* data set, set a counter for country values, and  */
        /* loop through to retrieve unique country values.  */
        /* Make a list for each country and insert into     */
        /* YEARLIST. Subset the data by YEAR and COUNTRY,   */
        /* loop through the data to fetch each item, insert */
        /* values into corresponding country list, then     */
        /* close data sets.                                 */
     rc=where(dsid,'year='||quote(year));
     rc=sort(dsid,'country','/nodupkey out=temp2');
     rc=where(dsid);
     temp2id=open('temp2');
     call set(temp2id);
     cnt2=0;
     do while(fetch(temp2id)=0);
        cnt2 + 1;
        rc=insertl(getiteml(yearlist,cnt),makelist(),
                   -1,country);
        rc=where(dsid,'year='||quote(year)||
                ' and country= '||quote(country));
          do while(fetch(dsid)=0);
             rc=insertc(getiteml(getiteml(yearlist,cnt),
                       cnt2),item,-1);
             end;
          rc=where(dsid,'undo');
          end;
     end;
     dsid=close(dsid);
     tempid=close(tempid);
     temp2id=close(temp2id);

        /* Display the contents of the master list for      */
        /* reference and save the list permanently in       */
        /* an SLIST catalog entry. Then delete the list     */
        /* and recursively delete the sublists.             */
     call putlist(yearlist,'',0);
     rc=savelist('slist','sasuser.pgms.a.slist',yearlist);
     rc=dellist(yearlist,'y');
     return;

________________________________________________________________________

       /* Make an SCL list to receive the stored list and   */
       /* retrieve it using the FILLIST function.  Make a   */
       /* list to store individual year values and loop     */
       /* through to retrieve the values.  Hide CNTRIES     */
       /* and ITEMSL listboxes until a year value has       */
       /* been selected.                                    */
    length year country $ 8;

  INIT:
     listid=makelist();
     rc=fillist('slist','sasuser.pgms.a.slist',listid);
     yearlist=makelist();
     do i = 1 to listlen(listid);
        name=nameitem(listid,i);
        rc=insertc(yearlist,name,-1);
     end;
     call notify('cntries','_hide_');
     call notify('itemsl','_hide_');
     return;

________________________________________________________________________

     /* When a year is selected, extract corresponding      */
     /* list and store it in TEMPYEAR. Retrieve country     */
     /* names from TEMPYEAR and store them in TEMPLIST.     */
     /* Hide ITEMSL listbox until a country is selected.    */  
  YEARS:
     call notify('years','_get_last_sel_',row,issel,year);
     tempyear=getniteml(listid,year);
     if templist = . then templist=makelist();
     else rc=clearlist(templist,'y');
     do j=1 to listlen(tempyear);
        cname=nameitem(tempyear,j);
        rc=insertc(templist,cname,-1);
     end;
     call notify('cntries','_unhide_');
     call notify('cntries','_update_');
     call notify('itemsl','_hide_');
     return;

________________________________________________________________________

     /* Extract corresponding list from TEMPYEAR, store     */
     /* it in ITEMS and unhide ITEMSL listbox when a        */
     /* country is selected.                                */
  CNTRIES:
     call notify('cntries','_get_last_sel_',row2,
                issel2,country);
     items=getniteml(tempyear,country);
     call notify('itemsl','_unhide_');
     call notify('itemsl','_update_');
     return;

     /* Recursively delete the lists                        */
  TERM:
     rc=dellist(yearlist,'y');
     rc=dellist(tempyear,'y');
     rc=dellist(templist,'y');
     return;