BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Stepik
Obsidian | Level 7

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;
      else 
           if  o='false' and x=1 then A = RA1*m/l; 
           else
                if o='true' and x=1 then A = RA1*m*l;
        else 
                     if 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.fac
     predictedA = Acalc(er, wer, tyu, fgh, sae, sdr);
     format er, wer, tyu, fgh, sae best12. sdr char8.;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;
      else 
           if  o='false' and x=1 then A = RA1*m/l; 
           else
                if o='true' and x=1 then A = RA1*m*l;
        else 
                     if 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.fac
     predictedA = Acalc(er, wer, tyu, fgh, sae, sdr);
     format er, wer, tyu, fgh, sae best12. sdr char8.;
Run;

 

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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.

 

PaigeMiller_0-1663012019648.png

--
Paige Miller
Stepik
Obsidian | Level 7

;*';*";*/;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=.

PaigeMiller
Diamond | Level 26

Repeating: Please copy the log as text and paste it into the window that appears when you click on the </> icon.

--
Paige Miller
Stepik
Obsidian | Level 7
;*';*";*/;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=.
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
Stepik
Obsidian | Level 7
I have just renamed it to present here, it is a character in origin
ballardw
Super User

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;
      else 
           if  o='false' and x=1 then A = RA1*m/l; 
           else
                if o='true' and x=1 then A = RA1*m*l;
        else 
                     if 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.fac
     predictedA = Acalc(er, wer, tyu, fgh, sae, sdr);
     format er, wer, tyu, fgh, sae best12. sdr char8.;
Run;

 

Stepik
Obsidian | Level 7
I also needed to add $ in a function statement apart from renaming true/false to TRUE/FALSE:

function Acalc(x, y, z, l, m, o $);

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

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.

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
  • 8 replies
  • 709 views
  • 0 likes
  • 3 in conversation