i have used the following code to generate the impulse response result tables successfully, however, i don't know how to plot these impulse responses using codes in this context. i urgently need the solution.
"
data dd1;
set work.dd;
/* Choose a period */
if Year= 2015.4 then output;
run;
filename c1 "/home/m182679152860/myfolder/Impulses_2015q4.xls"; /* Excel file output name */
/* Macro to show impulse responses */
%macro impulse(nnctry,nnperiod);
%do k = 1 %to &nnctry;
%let ctry = P[&k,1:&nnctry];
%do n = 2 %to &nnperiod;"
%let m1 = %eval(&nnctry*(&n-1)+1);
%let m2 = %eval(&nnctry*(&n));
ctry&k = &ctry//P[&k,&m1:&m2];
%let ctry = ctry&k;
%end;
%end;
%mend;
/* Macro to show cumulative impulse responses after 4 quarters */
%macro cumirf(nnctry);
%let irf = ctry1[1,1:&nnctry]+ctry1[2,1:&nnctry]+ctry1[3,1:&nnctry]+ctry1[4,1:&nnctry];
%do n = 2 %to &nnctry;
%let irf1 = ctry&n[1,1:&nnctry]+ctry&n[2,1:&nnctry]+ctry&n[3,1:&nnctry]+ctry&n[4,1:&nnctry];
irfcum = &irf//&irf1;
%let irf = irfcum;
%end;
%mend;
data est;
set est1.est1;
a5=-a5; b5=-b5; c5=-c5; d5=-d5; e5=-e5; f5=-f5; g5=-g5;
z1=1;
run;
proc iml;
reset noname;
use est;
read all;
r0_1= z1||a5||a5||a5||a5||a5||a5;
r0_2= b5||z1||b5||b5||b5||b5||b5;
r0_3= c5||c5||z1||c5||c5||c5||c5;
r0_4= d5||d5||d5||z1||d5||d5||d5;
r0_5= e5||e5||e5||e5||z1||e5||e5;
r0_6= f5||f5||f5||f5||f5||z1||f5;
r0_7= g5||g5||g5||g5||g5||g5||z1;
BB0=r0_1//r0_2//r0_3//r0_4//r0_5//r0_6//r0_7;
r1_1= a1||a6||a6||a6||a6||a6||a6;
r1_2= b6||b1||b6||b6||b6||b6||b6;
r1_3= c6||c6||c1||c6||c6||c6||c6;
r1_4= d6||d6||d6||d1||d6||d6||d6;
r1_5= e6||e6||e6||e6||e1||e6||e6;
r1_6= f6||f6||f6||f6||f6||f1||f6;
r1_7= g6||g6||g6||g6||g6||g6||g1;
BB1=r1_1//r1_2//r1_3//r1_4//r1_5//r1_6//r1_7;
C=a0//b0//c0//d0//e0//f0//g0;
/*Weighting matrix*/
use dd1;
read all;
W1=W1_1||W1_2||W1_3||W1_4||W1_5||W1_6||W1_7;
W2=W2_1||W2_2||W2_3||W2_4||W2_5||W2_6||W2_7;
W3=W3_1||W3_2||W3_3||W3_4||W3_5||W3_6||W3_7;
W4=W4_1||W4_2||W4_3||W4_4||W4_5||W4_6||W4_7;
W5=W5_1||W5_2||W5_3||W5_4||W5_5||W5_6||W5_7;
W6=W6_1||W6_2||W6_3||W6_4||W6_5||W6_6||W6_7;
W7=W7_1||W7_2||W7_3||W7_4||W7_5||W7_6||W7_7;
W=W1//W2//W3//W4//W5//W6//W7;
BW0=BB0#W;
BW1=-BB1#W;
invBW0=inv(BW0);
A0=invBW0*C;
A1=-invBW0*BW1;
I7=I(7);
CC={SA,US,CHINA,INDIA,JAPAN,BRAZIL,EU};
AR = BW0||BW1;
MA = I7;
P = ratio(ar, ma, 20, 7);
%impulse(7,20);
%cumirf(7);
/*Generate output to excel file*/
ods tagsets.excelxp
file=c1
style=minimal;
print 'Weighting matrix',W[colname=cc format=5.5];
print 'SA impulse responses',ctry1[colname=cc format=5.3];
print 'US impulse responses',ctry2[colname=cc format=5.3];
print 'China impulse responses',ctry3[colname=cc format=5.3];
print 'India impulse responses',ctry4[colname=cc format=5.3];
print 'Japan impulse responses',ctry5[colname=cc format=5.3];
print 'Brazil impulse responses',ctry6[colname=cc format=5.3];
print 'Cumulative impulse responses after 4 quarters', irfcum[colname=cc format=5.3];
ods tagsets.excelxp close;
Without data, I cannot run your program. I also do not know what an impulse response is. It looks like maybe you want a plot of the countries/regions versus the ctry1-ctry6 values(?), But do you want a bar chart? A needle plot? Or even a line plot?
You will have the most flexibility if you write the values from the IML vectors into a SAS data set and then use PROC SGPLOT to plot the data. I have invented some data for illustration. The following calls create a bar plot and a needle plot.
data Have;
length CC $6;
input CC ctry;
datalines;
SA 1.2
US 3.4
CHINA 5.6
INDIA 4.7
JAPAN 3.8
BRAZIL 2.9
EU 4.0
;
proc sgplot data=Have;
vbar CC / response=ctry;
run;
proc sgplot data=Have;
needle x=CC y=ctry / markers;
run;
thank you very much. the attachment is my data set, how can i read this into a new data set by using proc sgplot ? what i should i write under datalines? and what syntax should use instead of " needle" and "graph"it out in sas?
this is the graph that i want to produce via sas.
Since you are a beginner, and the data is in separate variables, the simplest syntax is to use multiple SERIES statements:
Title "Chart Title";
proc sgplot data=MyData;
series x=Time y=SA;
series x=Time y=US;
series x=Time y=CHINA;
series x=Time y=INDIA;
series x=Time y=JAPAN;
series x=Time y=BRAZIL;
series x=Time y=EU;
run;
I'll leave it to others to show you how to get the data into a SAS data set.
thank you very much, i have figured it out.
Oh, by the way, you don't need those macros. The SAS/IML language has DO loops, so you can program the loops directly in IML. For example, the logic for the %impulse macro would look something like the following (untested, for illustration only):
/* %impulse(7,20); */
nnctry = 7; nnperiod = 20;
do k = 1 to nnctry;
ctry = P[k,1:nnctry];
do n = 2 to nnperiod;
m1 = nnctry*(n-1)+1;
m2 = nnctry*n;
ctry = ctry//P[k,m1:m2];
end;
end;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.