Programming the statistical procedures from SAS

Proc Score Intermediate Matrix

Reply
New Contributor
Posts: 4

Proc Score Intermediate Matrix

Proc Score scores a dataset using parameters from Proc Reg and provides you with a final estimate on the dependent variable. Is there a way to get the intermediate results? That is, can you get an X*Beta matrix with BY statement functionality without hand coding the multiplication? I have large confidential data, so the following fake data is provided as an example. Consider a model estimating a bank's return on investment (ROI) as a function of the time the account has been open, the balance in the account, and the average times the customer visits a branch each month: 

 

DATA WORK.TESTFILE;
INFILE DATALINES DLM=',';
INPUT MBR_NO ACCT_TYPE $ ROI YEARS_OPEN BALANCE VISIT_PER_MO ;
DATALINES;
01,C,0.515,5,11885,1
02,C,0.964,6,6023,0
03,S,0.735,2,9078,3
04,S,0.504,1,181,4
05,C,0.653,2,805,10
06,C,0.698,7,8321,4
07,S,0.108,6,3634,0
08,C,0.952,5,6500,7
09,C,0.309,1,7680,2
10,C,0.221,2,6969,2
11,C,0.352,13,8218,6
12,C,0.440,2,19995,1
13,S,0.782,4,1301,5
14,S,0.004,11,12871,3
15,C,0.525,8,12168,0
16,C,0.119,11,17187,4
17,S,0.169,7,6931,11
18,C,0.261,1,21894,7
19,C,0.406,2,6236,2
20,C,0.403,14,13017,1
;
RUN;

 

PROC SORT DATA=WORK.TESTFILE;
BY ACCT_TYPE;
RUN;

 

PROC REG DATA=WORK.TESTFILE OUTEST=WORK.TESTPARMS;
BY ACCT_TYPE ;
MODEL ROI = YEARS_OPEN BALANCE VISIT_PER_MO;
RUN;

PROC SCORE DATA=WORK.TESTFILE SCORE=WORK.TESTPARMS TYPE=PARMS;
BY ACCT_TYPE;
VAR ROI YEARS_OPEN BALANCE VISIT_PER_MO;
RUN;

 

The parameter for Visits_Per_Mo where Acct_Type = 'C' is -0.00242. I'm seeking a matrix where Visit_Per_Mo = 0 for Mbr_No = 15, -0.00242 for Mbr_No = 20, -0.00484 for Mbr_No = 9, etc. I'm not seeing anything in the documentation that will allow me to achieve this with Proc Score. Is there another procedure that will achieve the same thing? The dataset and number of variables in my actual dataset are large, so hand-coding the multiplication would prove time-consuming. 

Grand Advisor
Posts: 16,905

Re: Proc Score Intermediate Matrix

Can you post your expected output? 

I'm not seeing what an intermediate matrix would look like. 

 

Also, the multiplication should be very straightforward - using two arrays gets you there easily...if I understand what you're looking for. 

Trusted Advisor
Posts: 1,195

Re: Proc Score Intermediate Matrix

You can get that from the scored data set by adding out=data set name:

 

PROC SCORE DATA=WORK.TESTFILE SCORE=WORK.TESTPARMS out=WANT TYPE=PARMS;
BY ACCT_TYPE;
VAR ROI YEARS_OPEN BALANCE VISIT_PER_MO;
RUN;

 

proc print data=want;
run;

 

Model1 variable in want data set will give you the desired values.

 

 

New Contributor
Posts: 4

Re: Proc Score Intermediate Matrix

The Out= option does not provide the desired output. It does give a final sumproduct, but it does not provide the intermediate products prior to summation. 

New Contributor
Posts: 4

Re: Proc Score Intermediate Matrix

Given that the parameters from the regression look like this:

 

ACCT_TYPE_MODEL__TYPE__DEPVAR__RMSE_InterceptYEARS_OPENBALANCEVISIT_PER_MOROI
CMODEL1PARMSROI0.2528070.721278-0.00053-2.13E-05-0.00242-1
SMODEL1PARMSROI0.3073680.723341-0.084841.19E-050.007182-1

 

 

The desired results look like this: 

 

MBR_NOACCT_TYPYEARS_OPENBALANCEVISITS_PER_MO
1C-0.00267-0.25276-0.00242
2C-0.0032-0.128090
5C-0.00107-0.01712-0.01693
6C-0.00374-0.17696-0.00484
8C-0.00267-0.13824-0.01451
9C-0.00053-0.16333-0.00242
10C-0.00107-0.148210
11C-0.00694-0.17477-0.00967
12C-0.00107-0.42523-0.01693
15C-0.00427-0.25878-0.00725
16C-0.00587-0.36552-0.00967
18C-0.00053-0.46562-0.01209
19C-0.00107-0.13262-0.00725
20C-0.00747-0.27683-0.0266
3S-0.169690.1082550.07182
4S-0.084840.0021580.028728
7S-0.509070.0433350.014364
13S-0.339380.0155140.014364
14S-0.933290.1534870.007182
17S-0.593910.0826520
Grand Advisor
Posts: 16,905

Re: Proc Score Intermediate Matrix

You'll need to do the math. 

 

It should be relatively straightforward. Do you have a naming convention for your variables, that would help.

New Contributor
Posts: 4

Re: Proc Score Intermediate Matrix

Crud. I was afraid you'd say that. There is a naming convention, but, due to the confidentiality of the actual data, I cannot release it. Thanks for taking the time to look at this, regardless.
Grand Advisor
Posts: 16,905

Re: Proc Score Intermediate Matrix

Release fake names similar to what you did for your fake data. I won't have time to code anything now, someone else may, but it's a very straightforward calculation regardless of the number of values. 

SAS Super FREQ
Posts: 3,310

Re: Proc Score Intermediate Matrix

[ Edited ]

It sounds like you want to use the CODE statement to generate DATA step code. You can read about "Techniques for scoring a regression model in SAS."  The last section in the article describes the CODE statement and shows how to use it to score a model. You can examine the scoring code, and it automatically encodes the matrix multiplication so that you don't have to code it yourself.

 

Ask a Question
Discussion stats
  • 8 replies
  • 309 views
  • 3 likes
  • 4 in conversation