Meanwhile, I found that the user-defined function is not so practical because when calling it, I have to distinguish between a numeric value (without quotation marks) and alphanumeric value (with quotation marks). I have therefore returned to the solution with the macro again. Calling the nvalid function did not work, so I used the notdigit function, to disinguish between a value and a variable name. Here is my final solution. %macro pvalconv(data=,varin=,varout=,fac=);
%local char;
/* Treat missing value. */
%if "&varin."="" %then %do;
%let varin= .;
%end;
%let char= %substr(&varin.,1,1);
data &data.;
set &data.;
length _tmpstr $32;
length &varout. 8; /*numeric output variable in dataset*/
/* Set output variable (&varout.) */
%if "&varin."="." %then %do;
/* varin is missing */
&varout.= .;
%end;
%else %if %sysfunc(notdigit(&char.))=0 %then %do;
/*Parameter varin is a constant value*/
if findc("&varin.",'%') > 0 then do;
/*constant value with %*/
_tmpstr= scan("&varin.",1,'%');
&varout.= _tmpstr*&fac.;
end;
else do;
/*constant value without %*/
&varout.= input("&varin.",best.);
end;
%end;
%else %do;
/*Parameter varin is a dataset variable name*/
if vtype(&varin.)='C' then do;
/*alphanumeric Variable*/
if findc(&varin.,'%') > 0 then do;
/*alphanumeric Variable with %*/
_tmpstr= scan(&varin.,1,'%');
&varout.= _tmpstr*&fac.;
end;
else do;
/*alphanumeric Variable without %*/
&varout.= &varin.;
end;
end;
else if vtype(&varin.)='N' then do;
/*numeric variable*/
&varout.= &varin.;
end;
%end;
run;
%mend pvalconv;
/*Test the macro*/
data mydata;
myvarin='100%';
run;
%pvalconv(data=mydata,varin=100,varout=myvarout,fac=3.17);
%pvalconv(data=mydata,varin=100%,varout=myvarout,fac=3.17);
%pvalconv(data=mydata,varin=myvarin,varout=myvarout,fac=3.17);
... View more