SAS Training Self-Assessment

SAS Macro Language 2: Developing Macro Applications

Select the best answer for each question. When you are finished, click Submit Quiz.

  1. Which statement is false?

     a.   Macro functions are always processed during the execution of the DATA step.
     b.   Macro variable references in a DATA step are always resolved prior to DATA step compilation.
     c.   A %LET statement causes the macro processor to create a macro variable before a step is compiled.
     d.   The SYMPUTX routine creates a macro variable that is based on data calculated by the DATA step.


  2. Which DATA step creates a macro variable named Region and assigns to it a value of East or West based on the value of the data set variable Location?

     a.  
    data new;
       set sasuser.all;
       if Location='Boston' then do;
          call symputx('Region', 
                       'East');
       end;
       else do;
          call symputx('Region', 
                       'West');
       end;
    run;
     b.  
    data new;
       set sasuser.all;
       if Location='Boston' then do;
          %let Region=East;
       end;
       else do;
          %let Region=West;
       end;
    run;
     c.  
    data new;
       set sasuser.all;
       if Location='Boston' then do;
          call symputx(Region, "East");
       end;
       else do;
          call symputx(Region, "West");
       end;
    run;
     d.  
    data new;
       set sasuser.all;
       if Location='Boston' then do;
          symputx(Region, East);
       end;
       else do;
          symputx(Region, West);
       end;
    run;


  3. Which example correctly creates a macro variable in a PROC SQL step?

     a.  
    select Fee/Days format=dollar8. 
       into Daily_Fee from sasuser.all;
     b.  
    select Fee/Days format=dollar8.
       into :Daily_Fee from sasuser.all;
     c.  
    %let Daily_Fee=put(Fee/Days, dollar8.);
     d.  
    call symputx(Daily_Fee, put(Fee/Days, dollar8.);
    


  4. Consider the following global symbol table:

    Global Symbol Table
    TEACH1 Hallis, Dr. George
    TEACH2 Wickam, Dr. Alice
    TEACH3 Forest, Mr. Peter
    CRS 3

    What value does a reference to &&TEACH&CRS resolve to?

     a.   TEACH3
     b.   &TEACH3
     c.   &TEACH&CRS
     d.   Forest, Mr. Peter


  5. Which example defines a macro named Print that correctly implements parameters named vars and total?

     a.  
    %macro Print(&vars, &total);
       proc print data=classes;
          var vars;
          sum total;
       run;
    %mend Print;
     b.  
    %macro Print(vars, total);
       proc print data=classes;
          var &vars;
          sum &total;
       run;
    %mend Print;
     c.  
    %macro Print('vars', 'total');
       proc print data=classes;
          var &vars;
          sum &total;
       run;
    %mend Print;
     d.  
    %macro Print(vars, total);
       proc print data=classes;
          var :vars;
          sum :total;
       run;
    %mend Print;


  6. Which example creates a macro variable named Class in a local symbol table? Assume that each program is submitted in a new SAS session.

     a.  
    data _null_;
       set sasuser.courses;
       %let Class=Course_Title;
    run;
     b.  
    data _null_;
       set sasuser.courses;
       call symputx('Class', Course_Title);
    run;
     c.  
    %macro sample(dsn);
       %global Class;
       %let Class=Course_Title;
       data _null_;
          set &dsn;
       run;
    %mend;
    
    %sample(courses)
     d.  
    %macro sample(dsn);
       %let Class=Course_Title;
       data _null_;
          set &dsn;
       run;
    %mend;
    
    %sample(courses)


  7. Assuming that you began your SAS session today, which statement correctly sets the macro variable CurrDate to today's date?

     a.   %let CurrDate = today();
     b.   %let CurrDate = %sysfunc(&sysdate);
     c.   %let CurrDate = put(today(),worddate.);
     d.   %let CurrDate = %sysfunc(today(),worddate.);


  8. Which example correctly compares the value of the macro variable MacVar to a null value?

     a.  
    %macro test;
       %if &MacVar = %then %do;
          %put value of MacVar is null;
       %end;
    %mend;
     b.  
    %macro test;
       %if &MacVar = _null_ %then %do;
          %put value of MacVar is null;
       %end;
    %mend;
     c.  
    %macro test;
       %if &MacVar = "  " %then %do;
          %put value of MacVar is null;
       %end;
    %mend;
     d.  
    %macro test;
       %if "MacVar" = %then %do;
          %put value of MacVar is null;
       %end;
    %mend;


  9. Which example creates a sequence of macro variables, DSN1 through DSNn?

     a.  
    data _null_;
       set sashelp.vstabvw; 
          where libname='WORK';
          call symputx('DSN'||_n_, memname);
    run;
     b.  
    data _null_;
       set sashelp.vstabvw; 
          where libname='WORK';
          call symputx('DSN', memname);
    run;
     c.  
    data _null_;
       set sashelp.vstabvw; 
          where libname='WORK';
          call symputx('DSN'||left(_n_), memname);
    run;
     d.  
    data _null_;
       set sashelp.vstabvw; 
          where libname='WORK';
          %let DSN=memname;
    run;


  10. Consider the following global symbol table:

    Global Symbol Table
    DSN1 employee
    DSN2 payroll
    DSN3 customer
    N 3


    Which macro program produces a listing report for each of the data set names stored in DSN1 through DSN3?

     a.  
    %macro Test;
       %do i=1 %to n;
          proc print data=&&DSN&i;
          run;
       %end;
    %mend;
     b.  
    %macro Test;
       %do i=1 %to &n;
          proc print data=&&DSN&i;
          run;
       %end;
    %mend;
     c.  
    %macro Test;
       %do i=1 %to &n;
          proc print data=&DSN&i;
          run;
       %end;
    %mend;
     d.  
    %macro Test;
       %do &i=1 %to &n;
          proc print data=&&DSN&i;
          run;
       %end;
    %mend;