Using PROC FCMP to Create a Subroutine

The SUBROUTINE statement names the block of code that is processed and specifies the parameters. The OUTARGS statement specifies the parameters that the subroutine updates. The ENDSUB statement ends the definition of the subroutine. In the following example, the subroutine CALC_YEARS is defined to calculate years to maturity from SAS date variables:
subroutine calc_years(maturity, current_date, years);
   outargs years;
   years=(maturity - current_date) / 365.25;
endsub;
The following code is an example of calling the CALC_YEARS subroutine:
data _null_;
  myCD='23jul2017'd;
  now=today();
  how_many_years=.;
  call calc_years(myCD,now,how_many_years);
  put how_many_years=;
run;
The following table lists the differences between functions and subroutines:
Descriptions
Function
Subroutine
Accepts arguments
yes
yes
Modifies arguments
no
yes
Returns a value
yes
no
Is an expression
yes
no
Is a statement
no
yes
Can be part of a statement
yes
no
Begins with CALL
no
yes
For more information about PROC FCMP, see “PROC FCMP” in the Base SAS Procedures Guide.
..................Content has been hidden....................

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