Dear team,
Can someone assist for the below problem, appearing once the programme is run:
"ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 10 at line 18 column 13.
The statement was:
0 (18:13) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 13 at line 21 column 18.
The statement was:
0 (21:18) ##dbl4 = (p=.) = Move N<=C("true") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 16 at line 24 column 23.
The statement was:
0 (24:23) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) ^= 1
ERROR: Exception occurred during subroutine call."
Code
I would look to the definition of the parameters. It appears that you have defined your parameter o as numeric (no $ anywhere) but then use it as a character value in comparisons.
Personally unless there are values other than true, false and missing involved defining boolean type values a character is, IMHO, just waiting to have an issue of some kind. SAS will treat numeric 1 as true and 0 as false and you never have to worry about case: "True" is not equal to "true" is not equal to "TRUE". Plus I find it much easier to get summary statistics of "how many true" values with SUM function; percent true is Mean; all the same is Range =0; any true is MAX=1; any false is MIN=0 and few other things are much easier with numeric than character.
@Stepik wrote:
Dear team,
Can someone assist for the below problem, appearing once the programme is run:
"ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 10 at line 18 column 13.
The statement was:
0 (18:13) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 13 at line 21 column 18.
The statement was:
0 (21:18) ##dbl4 = (p=.) = Move N<=C("true") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 16 at line 24 column 23.
The statement was:
0 (24:23) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) ^= 1
ERROR: Exception occurred during subroutine call."
Code
proc fcmp outlib=stepik.functions.a;function Acalc(x, y, z, l, m, o);R = 0.03*35;G = QUANTILE('NORMALTGAUSS', x);N = CDF('NORMALTGAUSS', 1);RA1 = y*z;RA2 = y*N;format R best12.;format G best12.;format N best12.;format RA1 best12.;format RA2 best12.;If l = . then A = RA1*m;elseif o='false' and x=1 then A = RA1*m/l;elseif o='true' and x=1 then A = RA1*m*l;elseif o='false' and x ne 1 then A = RA2*m/l;else RA = RA2*m*l;return (A);endsub;run;options cmplib=(stepik.functions);Data Sample;Set 123.facpredictedA = Acalc(er, wer, tyu, fgh, sae, sdr);format er, wer, tyu, fgh, sae best12. sdr char8.;Run;
Please do not detach the error messages from the code in the log. Show us the ENTIRE log for PROC FCMP, not just the error messages. Please copy the log as text and paste it into the window that appears when you click on the </> icon.
;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='TE_A.sas';
4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTPATHHOST='';
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='\\...;
9 %LET _SASPROGRAMFILEHOST='NLL7894564';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 %macro HTML5AccessibleGraphSupported;
15 %if %_SAS_VERCOMP(9, 4, 4) >= 0 %then ACCESSIBLE_GRAPH;
16 %mend;
17 FILENAME EGHTML TEMP;
18 ODS HTML5(ID=EGHTML) FILE=EGHTML
19 OPTIONS(BITMAP_MODE='INLINE')
20 %HTML5AccessibleGraphSupported
21 ENCODING='utf-8'
22 STYLE=HTMLBlue
23 NOGTITLE
24 NOGFOOTNOTE
25 GPATH=&sasworklocation
26 ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 libname ...;
NOTE: Credential obtained from SAS metadata server.
NOTE: Libref RDM was successfully assigned as follows:
Engine: SQLSVR
Physical Name: 523
29
30 options cmplib=(stepik.functions);
31 Data Sample;
32 Set 123.fac;
33 where ...;
34 predictedA = Acalc(er, wer, tyu, fgh, sae, sdr);
35 format er, wer, tyu, fgh, sae best 12. sdr char8.;
36 Run;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
34:92
NOTE: Invalid numeric data, sme_support_ind='FALSE' , at line 34 column 92.
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 10 at line 18 column 13.
The statement was:
0 (18:13) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 13 at line 21 column 18.
The statement was:
0 (21:18) ##dbl4 = (p=.) = Move N<=C("true") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 16 at line 24 column 23.
The statement was:
0 (24:23) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) ^= 1
ERROR: Exception occurred during subroutine call.
... sdr=FALSE predictedA=.
Repeating: Please copy the log as text and paste it into the window that appears when you click on the </> icon.
;*';*";*/;quit;run; 2 OPTIONS PAGENO=MIN; 3 %LET _CLIENTTASKLABEL='TE_A.sas'; 4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project'; 5 %LET _CLIENTPROJECTPATH=''; 6 %LET _CLIENTPROJECTPATHHOST=''; 7 %LET _CLIENTPROJECTNAME=''; 8 %LET _SASPROGRAMFILE='\\...; 9 %LET _SASPROGRAMFILEHOST='NLL7894564'; 10 11 ODS _ALL_ CLOSE; 12 OPTIONS DEV=SVG; 13 GOPTIONS XPIXELS=0 YPIXELS=0; 14 %macro HTML5AccessibleGraphSupported; 15 %if %_SAS_VERCOMP(9, 4, 4) >= 0 %then ACCESSIBLE_GRAPH; 16 %mend; 17 FILENAME EGHTML TEMP; 18 ODS HTML5(ID=EGHTML) FILE=EGHTML 19 OPTIONS(BITMAP_MODE='INLINE') 20 %HTML5AccessibleGraphSupported 21 ENCODING='utf-8' 22 STYLE=HTMLBlue 23 NOGTITLE 24 NOGFOOTNOTE 25 GPATH=&sasworklocation 26 ; NOTE: Writing HTML5(EGHTML) Body file: EGHTML 27 28 libname ...; NOTE: Credential obtained from SAS metadata server. NOTE: Libref RDM was successfully assigned as follows: Engine: SQLSVR Physical Name: 523 29 30 options cmplib=(stepik.functions); 31 Data Sample; 32 Set 123.fac; 33 where ...; 34 predictedA = Acalc(er, wer, tyu, fgh, sae, sdr); 35 format er, wer, tyu, fgh, sae best 12. sdr char8.; 36 Run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 34:92 NOTE: Invalid numeric data, sme_support_ind='FALSE' , at line 34 column 92. ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 10 at line 18 column 13. The statement was: 0 (18:13) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) = 1 ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 13 at line 21 column 18. The statement was: 0 (21:18) ##dbl4 = (p=.) = Move N<=C("true") & (x=0.01) = 1 ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 16 at line 24 column 23. The statement was: 0 (24:23) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) ^= 1 ERROR: Exception occurred during subroutine call. ... sdr=FALSE predictedA=.
Please look at the data set 123.fac with your own eyes, and see where a variable which should be numeric is actually character.
By the way, how does any of this work with an illegal library name such as 123?
I would look to the definition of the parameters. It appears that you have defined your parameter o as numeric (no $ anywhere) but then use it as a character value in comparisons.
Personally unless there are values other than true, false and missing involved defining boolean type values a character is, IMHO, just waiting to have an issue of some kind. SAS will treat numeric 1 as true and 0 as false and you never have to worry about case: "True" is not equal to "true" is not equal to "TRUE". Plus I find it much easier to get summary statistics of "how many true" values with SUM function; percent true is Mean; all the same is Range =0; any true is MAX=1; any false is MIN=0 and few other things are much easier with numeric than character.
@Stepik wrote:
Dear team,
Can someone assist for the below problem, appearing once the programme is run:
"ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 10 at line 18 column 13.
The statement was:
0 (18:13) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 13 at line 21 column 18.
The statement was:
0 (21:18) ##dbl4 = (p=.) = Move N<=C("true") & (x=0.01) = 1
ERROR: Unable to convert a character value to a numeric value in function 'Acalc' in statement number 16 at line 24 column 23.
The statement was:
0 (24:23) ##dbl4 = (p=.) = Move N<=C("false") & (x=0.01) ^= 1
ERROR: Exception occurred during subroutine call."
Code
proc fcmp outlib=stepik.functions.a;function Acalc(x, y, z, l, m, o);R = 0.03*35;G = QUANTILE('NORMALTGAUSS', x);N = CDF('NORMALTGAUSS', 1);RA1 = y*z;RA2 = y*N;format R best12.;format G best12.;format N best12.;format RA1 best12.;format RA2 best12.;If l = . then A = RA1*m;elseif o='false' and x=1 then A = RA1*m/l;elseif o='true' and x=1 then A = RA1*m*l;elseif o='false' and x ne 1 then A = RA2*m/l;else RA = RA2*m*l;return (A);endsub;run;options cmplib=(stepik.functions);Data Sample;Set 123.facpredictedA = Acalc(er, wer, tyu, fgh, sae, sdr);format er, wer, tyu, fgh, sae best12. sdr char8.;Run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.