I construct 3 matrices of interest (av, fd0 and tcof / denoted V, F and B later) from 3 sas datasets (WIO, WFD and WVA) through using a macro and do loop below. I want to transform V, F and B to sas datasats in the end of the loop (highlighted in bold in the code below), but I am not able to do this. Any suggestions on what I can do to fix this?
The only error message I get in the log is:
Also: when I try to print the matrices after running the code below (using: proc print data = F; run;) nothing happens.
Code:
%Macro trade;
%do j = 2000 %to 2014;
data tmpi; set iiodat.WIO;
if year = &j;
run;
data va; set iiodat.WVA(keep = ctr sec year tva tout);
if year = &j;
run;
data invgo; set invout;
if year = &j;
run;
data fd0(drop = year); set iiodat.WFD;
if year = &j;
run;
data texpfd(drop=year); set iiodat.texpfgd;
if year = &j;
run;
data texpi(drop = year); set iiodat.texpint;
if year = &j;
if sec = "TOT" then delete;
run;
proc iml;
use tmpi(drop=year);
read all var _all_ into IO;
use va(keep=tout);
read all var _all_ into GO;
use va(keep=tva);
read all var _all_ into VA;
use invgo(keep = invgo);
read all var _all_ into invgo;
use fd0;
read all var _all_ into fd0;
use texpi(drop = texpi);
read all var _all_ into expi;
use texpfd(drop = texpfd domdmd);
read all var _all_ into expf;
use texpfd(keep = domdmd);
read all var _all_ into dfd;
use texpfd(keep = texpfd);
read all var _all_ into texpf;
use texpi(keep = texpi);
read all var _all_ into texpi;
end;
A = IO#t(invgo);
av = VA#(invgo);
I2464 =I(2464);
/* lieontif inverse */
tcof = inv(i2464-a);
store a av tcof fd0;
/* I denote fd0 = F, av = V and tcof= B */
proc iml;
create F from fd0;
append from fd0;
close F;
create V from av;
append from av;
close V;
create B from tcof;
append from tcof;
close B;
end;
data F&i;
run;
data V&i;
run;
data B&i;
run;
%end;
%mend trade;
%trade;
Log:
The unbalanced quotes issue is probably from some previous drafts. Exit SAS and restart. In the future, you can submit the MAGIC STRING to eliminate close any open quotes/comments/etc.
In your program, I see at least two mistakes:
1. The END statement is used to complete a DO/END block. Perhaps you are confusing END with QUIT, which exits PROC IML.
2. When you type PROC IML, SAS exits any previous procedures and starts PROC IML in a fresh/new state. In your program you use PROC IML before you attempt to write the SAS data sets. That statement exits the previous program and clears memory, so the SAS data sets will not be written correctly. Delete the entire line just after the comment /* I denote fd0 = F, av = V and tcof= B */ .
I'll add that you don't nee the macro at all. SAS/IML can read multiple data sets in a single session, and supports where clauses so that you can read each year at a time. See
Read multiple data sets into SAS/IML
and for a very advanced example
Search all variables in all data sets
Or you can keep the macro. Your choice! 🙂
The unbalanced quotes issue is probably from some previous drafts. Exit SAS and restart. In the future, you can submit the MAGIC STRING to eliminate close any open quotes/comments/etc.
In your program, I see at least two mistakes:
1. The END statement is used to complete a DO/END block. Perhaps you are confusing END with QUIT, which exits PROC IML.
2. When you type PROC IML, SAS exits any previous procedures and starts PROC IML in a fresh/new state. In your program you use PROC IML before you attempt to write the SAS data sets. That statement exits the previous program and clears memory, so the SAS data sets will not be written correctly. Delete the entire line just after the comment /* I denote fd0 = F, av = V and tcof= B */ .
I'll add that you don't nee the macro at all. SAS/IML can read multiple data sets in a single session, and supports where clauses so that you can read each year at a time. See
Read multiple data sets into SAS/IML
and for a very advanced example
Search all variables in all data sets
Or you can keep the macro. Your choice! 🙂
I put the following magic string on function 12.
All I have to do is hit F12, highlight and hit RMB.
Takes about 1 second for me to fix the issue.
Works best in the more powerfull old text editor?, not EE, EG or SAS Studio
;;;;/*'*/ *);*};*];*/;/*"*/;%mend;run;quit;%end;end;run;endcomp;%utlfix;
%macro utlfix(dum);
* fix frozen sas and restore to invocation ;
dm "odsresults;clear;";
ods results off;
options ls=171 ps=65;run;quit;
ods listing;
ods select all;
ods excel close;
ods graphics off;
proc printto;run;
goptions reset=all;
endsubmit;
endrsubmit;
run;quit;
%utlopts;
%mend utlfix;
Thank you for the quick reply! It made things much clearer. I solved the problem by changing the placement for END / QUIT and PROC IML. I decided to only look at one year (since not all 14 are of interest and I have limited time at the moment to discover new fancy comands), and thus also not to use a macro. The code is below, if interested.
Thank you again!
data tmpi; set iiodat.WIO;
if year = 2000;
run;
data va; set iiodat.WVA(keep = ctr sec year tva tout);
if year = 2000;
run;
data invgo; set invout;
if year = 2000;
run;
data fd0; set iiodat.WFD;
if year = 2000;
run;
data fd0; set fd0(drop=year);
run;
data texpfd; set iiodat.texpfgd;
if year = 2000;
run;
data texpfd; set texpfd(drop=year);
run;
data texpi; set iiodat.texpint;
if year = 2000;
if sec = "TOT" then delete;
run;
data texpi; set texpi(drop=year);
run;
proc iml;
use tmpi(drop=year);
read all var _all_ into IO;
use va(keep=tout);
read all var _all_ into GO;
use va(keep=tva);
read all var _all_ into VA;
use invgo(keep = invgo);
read all var _all_ into invgo;
use fd0;
read all var _all_ into fd0;
use texpi(drop = texpi);
read all var _all_ into expi;
use texpfd(drop = texpfd domdmd);
read all var _all_ into expf;
use texpfd(keep = domdmd);
read all var _all_ into dfd;
use texpfd(keep = texpfd);
read all var _all_ into texpf;
use texpi(keep = texpi);
read all var _all_ into texpi;
texp = expi + expf;
A = IO#t(invgo);
av = VA#(invgo);
I2464 = I(2464);
/*Leontief inverse*/
tcof = inv(i2464-a);
store a av tcof fd0 dfd;
/* Create datasets from matrices */
create F from fd0;
append from fd0;
create av from av;
append from av;
create B from tcof;
append from tcof;
quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.