BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rileyd
Quartz | Level 8

Hey! I'm new to using Proc FCMP. This is my first attempt. Just experimenting with replacing some repetitive code that's a string of functions with a Proc FCMP function. However, I've run into a little trouble with the VVALUEX function that's in the string I'm trying to replace. Looking for a little help! Using Base SAS 9.4.

 

Here's an example of the code I'm trying to replace. I realize this may not make sense - just playing around with Proc FCMP.

 

LALAE_Lmtd_Paid_LDF_PLmt_Upper = Input(Left(VValueX(Catt('LALAE_',PLmt_Upper_LDF_Char,'Pd'))),8.);
LO_Lmtd_Incd_LDF_Ded_Lower = Input(Left(VValueX(Catt('LO_',Ded_Lower_LDF_Char,'Inc'))),8.);
XS_Incd_LDF_Ded_Lower = Input(Left(VValueX(Catt('XS_',Ded_Lower_XS_LDF_Char,'Inc'))),8.);
LALAE_Lmtd_Incd_LDF_100K = Input(Left(VValueX('LALAE_LDF_100kInc')),8.);

 

Here's the Proc FCMP code and error message:

Proc FCMP Outlib = My_Lib.functions.myfncs;
    Function MyFctrLkp(Fctr_To_Lkp $);
        Fctr = Input(Left(VValueX(Fctr_To_Lkp)),8.);
        Return(Fctr);
    EndSub;
Run;

ERROR: The VVALUEX function is only valid in the DATA step. User defined libraries will be searched for a
definition of this function.
NOTE: Numeric value converted to character for argument 1 of 'LEFT' operation.

ERROR: Cannot find a library containing subroutine VVALUEX.
NOTE: Execution aborted because of errors in program.

 

Here's what I'm trying to accomplish:

LALAE_Lmtd_Paid_LDF_PLmt_Upper = MyFctrLkp(Catt('LALAE_',PLmt_Upper_LDF_Char,'Pd'));
LO_Lmtd_Incd_LDF_Ded_Lower = MyFctrLkp(Catt('LO_',Ded_Lower_LDF_Char,'Inc'));
XS_Incd_LDF_Ded_Lower = MyFctrLkp(Catt('XS_',Ded_Lower_XS_LDF_Char,'Inc'));
LALAE_Lmtd_Incd_LDF_100K = MyFctrLkp('LALAE_LDF_100kInc');

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Variables in the program data vector are not accessible within a function.  Consider:

 

proc fCMP Outlib = work.functions.myfncs;
    Function Myfunct();
        Fctr = age;
        Return(Fctr);
    EndSub;
run;
options cmplib=work.functions;
data want;
  set sashelp.class;
  var=Myfunct();
  put var=;
run;

 

which results in VAR=. for all observations.  That's because you have to pass the value of age TO the function in the guise of a function argument (which may or may not also be named age).  Of course no message is generated - only missing values.

 

But VVALUEX is one layer worse, since it is supposed to have variable name as an argument and then go to the pdv to get the value for that variable.  The function compiler knows this, so it tells you VVALUEX can't be used within a function definition.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

1 REPLY 1
mkeintz
PROC Star

Variables in the program data vector are not accessible within a function.  Consider:

 

proc fCMP Outlib = work.functions.myfncs;
    Function Myfunct();
        Fctr = age;
        Return(Fctr);
    EndSub;
run;
options cmplib=work.functions;
data want;
  set sashelp.class;
  var=Myfunct();
  put var=;
run;

 

which results in VAR=. for all observations.  That's because you have to pass the value of age TO the function in the guise of a function argument (which may or may not also be named age).  Of course no message is generated - only missing values.

 

But VVALUEX is one layer worse, since it is supposed to have variable name as an argument and then go to the pdv to get the value for that variable.  The function compiler knows this, so it tells you VVALUEX can't be used within a function definition.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 970 views
  • 1 like
  • 2 in conversation