Programming the statistical procedures from SAS

How to make PROC LOGISTIC work when pprob is a variable, not a number

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

How to make PROC LOGISTIC work when pprob is a variable, not a number

Hi guys,

 

My task is very simple. I'm using PROC LOGISTIC with the argument ctable and pprob.

If I use pprob=0.5 (a number) my procedure runs. However, whenever I try an expression (say 10/100 or, more interestingly, a variable's name inside an expression like i/100) SAS returns the following error:

 

ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant, (.
 
I need to use this inside a macro and vary the values of pprobs from 0.01 to 1. I've attached code (in SAS Studio) and data. The part that does not run is the very last (the logistic_macro).
 
%macro logistic_macro; 
	%do i = 1 %to 100;
     	proc logistic data=WORK.GLMDesign outmodel=final_model noprint;
		class Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28 / param=glm;
		model VAR21(event='1')= Col3 Col4 Col7 Col8 Col9 Col13 Col22 Col23 Col27 Col28
			Col2  / link=logit technique=fisher ctable  pprob=%EVAL(&i./100) ;
		output out=preds predprobs=individual;
		score data=testset out=TestPred_new;
		run;
		proc freq data=TestPred_new;
    	table VAR21*I_VAR21 / out=CellCounts_new noprint;
		run;
		proc iml; /* using matrix language like in HW06 to make our lives easier */
		loss= j(100, 1, 0);  /*vector to store loss for different thresholds */
		use work.CellCounts_new; 
		read all var _ALL_ into M;
		close work.CellCounts_new;
		FalsePos = M[2,2] # 5; 
		FalseNeg = M[3,2]; 
		loss[i] = FalsePos + FalseNeg;
		print loss;
     %end; 
%mend;

%logistic_macro; *runs the macro;
I appreciate your help as usual!
Attachment

Accepted Solutions
Solution
a month ago
Occasional Contributor
Posts: 8

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to marianaalcos

That's strange. I just tried it with dummy data and it worked for me, meaning changing the option to

pprob=%SYSEVALF(&i./100)

 

 

View solution in original post


All Replies
Occasional Contributor
Posts: 8

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to marianaalcos

%EVAL won't give you the decimal accuracy that you need. Try %SYSEVALF instead.

%let i=1;
%put %EVAL(&i./100);
%put %SYSEVALF(&i./100);

If you were to run the above, here are the results printed to the log:

0
0.01
 

Contributor
Posts: 46

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to lrudolphi
Hi lrudolphi,

Thanks for the comments, but I still got the same error. I had actually tried SYSEVALF before with put, but it seems that the argument pprob will not accept it =/
Solution
a month ago
Occasional Contributor
Posts: 8

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to marianaalcos

That's strange. I just tried it with dummy data and it worked for me, meaning changing the option to

pprob=%SYSEVALF(&i./100)

 

 

Contributor
Posts: 46

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to lrudolphi
Hi Irudolphi,

I actually went back to the log and the ERROR message has changed, now it is displaying the following message:
"Matrix has not been set to a value".
So I guess the SYSEVALF worked.
Any ideas what may be causing the new error? Thanks a lot!
Occasional Contributor
Posts: 8

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to marianaalcos
Apologies, I am not too familiar with proc iml, so unfortunately cannot help solve that part. Glad the other part worked, though!
Contributor
Posts: 46

Re: How to make PROC LOGISTIC work when pprob is a variable, not a number

Posted in reply to lrudolphi
That's okay, I guess I'll just post a new question, because I used proc iml outside the macro and it worked. Thanks anyways!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 136 views
  • 2 likes
  • 2 in conversation