BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sjm
Fluorite | Level 6 sjm
Fluorite | Level 6

Hi All,

 

I am using a macro to compute cash flow and discount rate news from stock returns using the residuals and VAR coefficients. This part of the programme computes the news items and the variance contributions using the residuals from the regressions (saved in RES) and the VAR coefficient matrix (saved in COF). The computation is done separately for each of the 11 industries using a macro. 

 

When I run the macro, I get the error message seen in the attached SAS log.  The main problem is that my date variable YEARQ is excluded because of a type mismatch with ID_MAT.  This causes the macro to breakdown and prevents PROC IML from working further.

 

Would appreciate your expert advise on how to resolve this issue. Thanks.

 

proc datasets;
	delete x x1;
run;

/* THIS MACRO COMPUTES THE NEWS FOR EACH INDUSTRY SEPARATELY  */
%macro myloop;
	%do j=1 %to 11;
run;

data u;
	set vdc.res;
	if ind=&j;
run;

data g;
	set vdc.cof;
	if ind=&j;
run;

proc iml;
/* 	READ THE VECTORS OF RESIDUALS INTO A MATRIX CALLED RES_MAT, AND THE VAR COEFFICIENT MATRIX INTO COF_MAT.
	THE MATRIX ID_MAT KEEPS THE OBSERVATION ORDER
*/
use u;
read all var{ER EE EB} into res_mat;
read all var{gvkey yearq} into id_mat;
use g;
read all var {dmLOGR1 dmLOGE1 dmLOGBM1} into cof_mat;
e1={1 0 0};
e2={0 1 0};
ro=0.967;
/* USING RES_MAT AND COF_MAT, COMPUTE LAMBDA1 (LAM1) AND LAMBDA2 (LAM2), AND DISCOUNT RATE NEWS (NR) AND 
   EARNINGS NEW (NE)
*/
lam1=e1*ro*cof_mat*inv(I(3)-ro*cof_mat);
lam2=e1+lam1;
/*	TO COMPUTE EARNINGS NEWS DIRECTLY, REPLACE THE LINE ABOVE WITH lam2=e2*inv(I(3)-ro*cof_mat);
*/
Nr=(lam1*res_mat`)`;
Ne=(lam2*res_mat`)`;
/*	CREATE THE NEWS MATRIX FROM THE NR AND NE VECTORS, AND TRANSFER IT INTO A DATASET CALLED X. THE
	DATASET X CONTAINS THE OBSERVATION ID'S AS WELL AS THE NEWS ITEMS FOR THE INDUSTRY
*/
z=id_mat||Nr||Ne;
create x from z;
append from z;
quit;

data x;
	set x;
	ind=&j;
run;
/*	APPEND THE INDUSTRY INFORMATION IN X INTO A DATASET CALLED X1 WHICH CONTAINS THE NEWS ITEMS FOR 
	ALL INDUSTRIES
*/
proc datasets library=work;
	append base=work.x1 data=work.x force;
%end;
%mend myloop;
%myloop;
/*	AT THE END OF THE LOOP TRANSFER THE ENTIRE NEWS DATA INTO A PERMANENT DATA CALLED NEWS AND
	COMPUTE THE VARIANCES
*/
data cashdrnews;
	set x1;
	rename col1=gvkey col2=yearq col3=nr col4=ne;
run;
data vdc.cashdrnews;
	set cashdrnews;
	vr=nr**2;
	ve=ne**2;
	covre=nr*ne;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The problem is that you cannot concatenate character variables (id_mat) and numerical variables (Nr and Ne) into a matrix.  You are trying to create an output data set, so there are two ways to do this.

 

1. If you have SAS/IML 15.1 or later (that's SAS 9.4M6 or later), the CREATE and APPEND statements support multip[le matrices. Thus you can get your output data by using the following statements:

/* method 1: Requires SAS/IML 15.1 */
z = Nr||Ne;
create x from id_mat z;
append from id_mat z;
close;

2. Notice that the id_mat matrix is never used in the program. Thus, you can simply merge the Nr and Ne results with the data in the U data set, as follows:

/* method 2: Write new variables and merge with id_mat */
z = Nr||Ne;
create x from z;
append from z;
close;
QUIT;

data x;
merge u(keep=gvkey yearq) x;
run;


View solution in original post

9 REPLIES 9
Kurt_Bremser
Super User

Big, super-size hint free of any charge:

Rule #1 of macro development: start with working non-macro code.

So get your code to work for a single instance before making it dynamic.

I have never worked with IML, but from the log it seems you need to convert your year to a character variable first before using it in your IML code.

PaigeMiller
Diamond | Level 26

Unlike @Kurt_Bremser , I have lots of experience with PROC IML, but his advice is still valid: get code to work on one instance without macros first. If it doesn't work without macros, then it will not work with macros either.

 

Also, many of us do not download attachments. LOG should be copied as text and then pasted into the window that appears when you click on the </> icon.

--
Paige Miller
sjm
Fluorite | Level 6 sjm
Fluorite | Level 6

Thanks, Paige.  Here is the log:

 

3513 proc datasets;
3514 delete x x1;
3515 run;

NOTE: Deleting WORK.X (memtype=DATA).
NOTE: Deleting WORK.X1 (memtype=DATA).
3516
3517 /* THIS MACRO COMPUTES THE NEWS FOR EACH INDUSTRY SEPARATELY */
3518
3519 %macro myloop;
3520 %do j=1 %to 11;
3521 run;
3522
3523 data u;
3524 set vdc.res;
3525 if ind=&j;
3526 run;
3527
3528 data g;
3529 set vdc.cof;
3530 if ind=&j;
3531 run;
3532
3533 proc iml;
3534 /* READ THE VECTORS OF RESIDUALS INTO A MATRIX CALLED RES_MAT, AND THE VAR COEFFICIENT MATRIX INTO COF_MAT.
3535 THE MATRIX ID_MAT KEEPS THE OBSERVATION ORDER
3536 */
3537 use u;
3538 read all var{ER EE EB} into res_mat;
3539 read all var{gvkey yearq} into id_mat;
3540 use g;
3541 read all var {dmLOGR1 dmLOGE1 dmLOGBM1} into cof_mat;
3542 e1={1 0 0};
3543 e2={0 1 0};
3544 ro=0.967;
3545 /* USING RES_MAT AND COF_MAT, COMPUTE LAMBDA1 (LAM1) AND LAMBDA2 (LAM2), AND DISCOUNTRATE NEWS (NR) AND
3546 EARNINGS NEW (NE)
3547 */
3548 lam1=e1*ro*cof_mat*inv(I(3)-ro*cof_mat);
3549 lam2=e1+lam1;
3550 /* TO COMPUTE EARNINGS NEWS DIRECTLY, REPLACE THE LINE ABOVE WITH lam2=e2*inv(I(3)-ro*cof_mat);
3551 */
3552 Nr=(lam1*res_mat`)`;
3553 Ne=(lam2*res_mat`)`;
3554 /* CREATE THE NEWS MATRIX FROM THE NR AND NE VECTORS, AND TRANSFER IT INTO A DATASET CALLED X. THE
3555 DATASET X CONTAINS THE OBSERVATION ID'S AS WELL AS THE NEWS ITEMS FOR THE INDUSTRY
3556 */
3557 z=id_mat||Nr||Ne;
3558 create x from z;
3559 append from z;
3560 quit;
3561
3562 data x;
3563 set x;
3564 ind=&j;
3565 run;
3566 /* APPEND THE INDUSTRY INFORMATION IN X INTO A DATASET CALLED X1 WHICH CONTAINS THE NEWS ITEMS FOR
3567 ALL INDUSTRIES
3568 */
3569 proc datasets library=work;
3570 append base=work.x1 data=work.x force;
3571 %end;
3572 %mend myloop;
3573 %myloop;


NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.09 seconds
cpu time 0.06 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 1024 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4736 column 148
operands : id_mat, Nr, Ne
id_mat 1024 rows 1 col (character, size 6)
Nr 1024 rows 1 col (numeric)
Ne 1024 rows 1 col (numeric)

statement : ASSIGN at line 4736 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4736 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4736 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds

 

ERROR: File WORK.X.DATA does not exist.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was stopped there were 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: BASE data set does not exist. DATA file is being copied to BASE file.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.08 seconds
cpu time 0.04 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 196 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4745 column 148
operands : id_mat, Nr, Ne
id_mat 196 rows 1 col (character, size 6)
Nr 196 rows 1 col (numeric)
Ne 196 rows 1 col (numeric)

statement : ASSIGN at line 4745 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4745 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4745 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.03 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.06 seconds
cpu time 0.04 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 3450 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4754 column 148
operands : id_mat, Nr, Ne
id_mat 3450 rows 1 col (character, size 6)
Nr 3450 rows 1 col (numeric)
Ne 3450 rows 1 col (numeric)

statement : ASSIGN at line 4754 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4754 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4754 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 1447 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4763 column 148
operands : id_mat, Nr, Ne
id_mat 1447 rows 1 col (character, size 6)
Nr 1447 rows 1 col (numeric)
Ne 1447 rows 1 col (numeric)

statement : ASSIGN at line 4763 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4763 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4763 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.07 seconds
cpu time 0.03 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 7560 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4772 column 148
operands : id_mat, Nr, Ne
id_mat 7560 rows 1 col (character, size 6)
Nr 7560 rows 1 col (numeric)
Ne 7560 rows 1 col (numeric)

statement : ASSIGN at line 4772 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4772 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4772 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.03 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.07 seconds
cpu time 0.04 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 1011 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4781 column 148
operands : id_mat, Nr, Ne
id_mat 1011 rows 1 col (character, size 6)
Nr 1011 rows 1 col (numeric)
Ne 1011 rows 1 col (numeric)

statement : ASSIGN at line 4781 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4781 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4781 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.06 seconds
cpu time 0.04 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 1214 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4790 column 148
operands : id_mat, Nr, Ne
id_mat 1214 rows 1 col (character, size 6)
Nr 1214 rows 1 col (numeric)
Ne 1214 rows 1 col (numeric)

statement : ASSIGN at line 4790 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4790 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4790 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 995 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4799 column 148
operands : id_mat, Nr, Ne
id_mat 995 rows 1 col (character, size 6)
Nr 995 rows 1 col (numeric)
Ne 995 rows 1 col (numeric)

statement : ASSIGN at line 4799 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4799 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4799 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.07 seconds
cpu time 0.04 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 367 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4808 column 148
operands : id_mat, Nr, Ne
id_mat 367 rows 1 col (character, size 6)
Nr 367 rows 1 col (numeric)
Ne 367 rows 1 col (numeric)

statement : ASSIGN at line 4808 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4808 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4808 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 4322 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4817 column 148
operands : id_mat, Nr, Ne
id_mat 4322 rows 1 col (character, size 6)
Nr 4322 rows 1 col (numeric)
Ne 4322 rows 1 col (numeric)

statement : ASSIGN at line 4817 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4817 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4817 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.05 seconds
cpu time 0.04 seconds

 

NOTE: There were 22358 observations read from the data set VDC.RES.
NOTE: The data set WORK.U has 772 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

NOTE: There were 33 observations read from the data set VDC.COF.
NOTE: The data set WORK.G has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


NOTE: IML Ready
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.

operation : || at line 4826 column 148
operands : id_mat, Nr, Ne
id_mat 772 rows 1 col (character, size 6)
Nr 772 rows 1 col (numeric)
Ne 772 rows 1 col (numeric)

statement : ASSIGN at line 4826 column 136
ERROR: Matrix z has not been set to a value.

statement : CREATE at line 4826 column 154
ERROR: No data set is currently open for output.

statement : APPEND at line 4826 column 171
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 


NOTE: There were 0 observations read from the data set WORK.X.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


3574
3575
3576 /* AT THE END OF THE LOOP TRANSFER THE ENTIRE NEWS DATA INTO A PERMANENT DATA CALLED NEWS AND
3577 COMPUTE THE VARIANCES
3578 */

NOTE: Appending WORK.X to WORK.X1.
NOTE: There were 0 observations read from the data set WORK.X.
NOTE: 0 observations added.
NOTE: The data set WORK.X1 has 0 observations and 1 variables.
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.09 seconds
cpu time 0.06 seconds


3579 data cashdrnews;
3580 set x1;
3581 rename col1=gvkey col2=yearq col3=nr col4=ne;
3582 run;

WARNING: The variable col1 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable col2 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable col3 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable col4 in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 0 observations read from the data set WORK.X1.
NOTE: The data set WORK.CASHDRNEWS has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


3583 data vdc.cashdrnews;
3584 set cashdrnews;
3585 vr=nr**2;
3586 ve=ne**2;
3587 covre=nr*ne;
3588 run;

NOTE: Variable nr is uninitialized.
NOTE: Variable ne is uninitialized.
NOTE: There were 0 observations read from the data set WORK.CASHDRNEWS.
NOTE: The data set VDC.CASHDRNEWS has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

 

Kurt_Bremser
Super User

The fact that you still try to run your defective code from within the macro makes debugging it hard, as the macro breaks the direct connect of code and ERROR message that you have in non-macro code.

Pull your code out of the macro definition and make it work for a single instance.

PaigeMiller
Diamond | Level 26

The advice we have given you really supersedes the need to see the LOG. You really need to get this working for one instance without macros first. If you still having trouble getting this to work in one instance without macros, then show us the LOG of that code with no macros, following the instructions given above.

 

I mentioned the LOG because in the future, you will be wise to show us the log, not as an attachment but as text. And you didn't follow the instructions I gave which said "LOG should be copied as text and then pasted into the window that appears when you click on the </> icon." If, in the future, you need to show us a log, these instructions must be followed.

--
Paige Miller
Sajid01
Meteorite | Level 14

Hello @sjm 
I see that the first error is 
WARNING: Variable yearq excluded because of type mismatch with id_mat.
ERROR: (execution) Numeric argument should be character.
I think You should address this first. Do the necessary modifications to the code.
Further I would reiterate what others have said, first test the code before creating the macro.
Second use smaller datasets for testing and debugging purpose not the full datasets. 

Ksharp
Super User

Why not post it at IML forum and calling @Rick_SAS 

Rick_SAS
SAS Super FREQ

The problem is that you cannot concatenate character variables (id_mat) and numerical variables (Nr and Ne) into a matrix.  You are trying to create an output data set, so there are two ways to do this.

 

1. If you have SAS/IML 15.1 or later (that's SAS 9.4M6 or later), the CREATE and APPEND statements support multip[le matrices. Thus you can get your output data by using the following statements:

/* method 1: Requires SAS/IML 15.1 */
z = Nr||Ne;
create x from id_mat z;
append from id_mat z;
close;

2. Notice that the id_mat matrix is never used in the program. Thus, you can simply merge the Nr and Ne results with the data in the U data set, as follows:

/* method 2: Write new variables and merge with id_mat */
z = Nr||Ne;
create x from z;
append from z;
close;
QUIT;

data x;
merge u(keep=gvkey yearq) x;
run;


sjm
Fluorite | Level 6 sjm
Fluorite | Level 6
Thanks, Rick. Method 2 works!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2388 views
  • 6 likes
  • 6 in conversation