Scenario 1

Code Solution

Note: On the live exam, you will be evaluated both on the results of your code and the code itself. Your code should be similar to the following example code, but does not need to match exactly:
proc fcmp outlib=work.function.add;   /*1*/
   function adding(val);              /*2*/
      final=38+val;
      return(final);                  /*3*/
   endsub;                            /*4*/
run;

options cmplib=work.function;         /*5*/

data work.studentcost;                /*6*/
   set certadv.all;
   Final_Cost=adding(fee);            /*7*/
run;

proc print data=work.studentcost;     /*8*/
   var Student_Name Course_Code Fee Final_Cost;
run;
1 The FCMP procedure enables you to create custom functions using DATA step syntax. The OUTLIB= option specifies Work.Function as the table in which the Add package is stored. The Add package is a collection of routines that have unique names.
2 The FUNCTION statement specifies the function name and the function arguments, as well as whether the function returns a character or numeric value. The Adding custom function has one numeric argument named Val, and it returns a numeric value. The variable Final is computed as 38 plus the value of the function's argument.
3 The RETURN statement specifies the value of Final to be returned from the function.
4 The ENDSUB statement ends the syntax for the function.
5 The CMPLIB= option specifies Work.Function table for SAS to search for a package that contains the desired function.
6 The DATA step creates a temporary data set named Work.StudentCost. SAS reads Certadv.All data set to create Work.StudentCost.
7 The DATA step creates a new variable named Final_Cost. The Final_Cost encompasses the fee for the course and an additional student fee. The new variable references the custom function Adding. The function adds a constant value of 38 to the value of Fee. The function returns the value of Final, which is then assigned to the value of Final_Cost.
8 The PROC PRINT step displays the output data with only the specified variables: Student_Name, Course_Code, Fee, and Final_Cost.
Output 17.1 PROC PRINT of Work.StudentCost (partial output)
Partial Output: PROC PRINT of Work.StudentCost

Test Your Code Solution

  1. Correct Answer: 438
  2. Correct Answer: 688
Last updated: October 16, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset