Generate output of multiple graphs by changing one variable

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Generate output of multiple graphs by changing one variable

[ Edited ]

I want to generate multiple graphs by changing the value of "rotate" in the following code from 1 to 360 by 10 ,  (without manually changing the number after "rotate="). Is there a way of doing it without implementing complicated macros?

 

proc template;
define statgraph surface;
begingraph;
entrytitle 'Yield Data';
rangeattrmap name="yield_map";
range 45-52.24 / rangecolormodel=(darkred);
range 52.25-56.53 / rangecolormodel=(red);
range 56.54-60.82 / rangecolormodel=(yellow);
range 60.83-65.11 / rangecolormodel=(green);
range 65.12-70 / rangecolormodel=(darkgreen);
endrangeattrmap;
rangeattrvar attrvar=yieldvar var=yield attrmap="yield_map";
layout overlay3d / rotate=10 tilt=90;
surfaceplotparm x=Latitude y=Longitude z=yield / surfacetype=fillgrid
colorresponse=yieldvar name="surface";
continuouslegend "surface";
endlayout;
endgraph;
end;
run;

ods graphics / width=640px height=640px;
proc g3grid data=surface_data out=gridded;
grid Longitude*Latitude=Yield / spline
axis1=1 to 25 by 1
axis2=1 to 13 by 1;
run;
proc sort data=gridded; by Longitude Latitude; run;

proc sgrender data=gridded template=surface;
run;

quit;

 

 

 


Accepted Solutions
Solution
‎12-11-2016 11:16 PM
Super User
Posts: 1,107

Re: Generate output of multiple graphs by changing one variable

A small change, i just realised that by increment will not work in %do loop. Hence i updated the code as below. I tested this and it is working. Please try and let me know if its working for you



%macro test;
%do i=1 %to 36;
%let j=%eval(&i*10);
proc sgrender data=gridded template=surface;
dynamic range1="&j";
run;
quit;
%end;
%mend;

%test;
Thanks,
Jag

View solution in original post


All Replies
Super User
Posts: 1,107

Re: Generate output of multiple graphs by changing one variable

[ Edited ]

Try the dynamic approach in proc template

 

proc template;
define statgraph surface;

dynamic range;
begingraph;
entrytitle 'Yield Data';
rangeattrmap name="yield_map";
range 45-52.24 / rangecolormodel=(darkred);
range 52.25-56.53 / rangecolormodel=(red);
range 56.54-60.82 / rangecolormodel=(yellow);
range 60.83-65.11 / rangecolormodel=(green);
range 65.12-70 / rangecolormodel=(darkgreen);
endrangeattrmap;
rangeattrvar attrvar=yieldvar var=yield attrmap="yield_map";
layout overlay3d / rotate=range tilt=90;
surfaceplotparm x=Latitude y=Longitude z=yield / surfacetype=fillgrid
colorresponse=yieldvar name="surface";
continuouslegend "surface";
endlayout;
endgraph;
end;
run;

ods graphics / width=640px height=640px;
proc g3grid data=surface_data out=gridded;
grid Longitude*Latitude=Yield / spline
axis1=1 to 25 by 1
axis2=1 to 13 by 1;
run;
proc sort data=gridded; by Longitude Latitude; run;

 

%macro test;

%do i=10 %to 360 by 10;
proc sgrender data=gridded template=surface;

dynamic range="&i";

run;

%end;
%mend;

quit;

Thanks,
Jag
Contributor
Posts: 23

Re: Generate output of multiple graphs by changing one variable

Hello Jag,

Thanks for the idea, however, No output is generated with this modification.

Is there a way to use array do loop or simply do loop?

Contributor
Posts: 23

Re: Generate output of multiple graphs by changing one variable

No Error but No output either
Super User
Posts: 1,107

Re: Generate output of multiple graphs by changing one variable

[ Edited ]

Did you try calling the macro with %test like below

%macro test;

%do i=10 %to 360 by 10;
proc sgrender data=gridded template=surface;

dynamic range="&i";

run;

quit;

%end;
%mend;

 

%test;

Thanks,
Jag
Contributor
Posts: 23

Re: Generate output of multiple graphs by changing one variable

I tried "%test;" instead of "%macro test;" Still no output
Super User
Posts: 1,107

Re: Generate output of multiple graphs by changing one variable

[ Edited ]

Please try running the entire below code

 

proc template;
define statgraph surface;

dynamic range1;
begingraph;
entrytitle 'Yield Data';
rangeattrmap name="yield_map";
range 45-52.24 / rangecolormodel=(darkred);
range 52.25-56.53 / rangecolormodel=(red);
range 56.54-60.82 / rangecolormodel=(yellow);
range 60.83-65.11 / rangecolormodel=(green);
range 65.12-70 / rangecolormodel=(darkgreen);
endrangeattrmap;
rangeattrvar attrvar=yieldvar var=yield attrmap="yield_map";
layout overlay3d / rotate=range1 tilt=90;
surfaceplotparm x=Latitude y=Longitude z=yield / surfacetype=fillgrid
colorresponse=yieldvar name="surface";
continuouslegend "surface";
endlayout;
endgraph;
end;
run;

ods graphics / width=640px height=640px;
proc g3grid data=surface_data out=gridded;
grid Longitude*Latitude=Yield / spline
axis1=1 to 25 by 1
axis2=1 to 13 by 1;
run;
proc sort data=gridded; by Longitude Latitude; run;

 

%macro test;

%do i=10 %to 360 by 10;
proc sgrender data=gridded template=surface;

dynamic range1="&i";

run;

quit;

%end;
%mend;

 

%test;

 

Thanks,
Jag
Contributor
Posts: 23

Re: Generate output of multiple graphs by changing one variable

I modified my code as :

 

 

Data surface_data;
input longitude latitude yield;
datalines;
25 1 9.4375
25 2 9.505882353
25 3 9.431578947
25 4 9.363636364
25 5 9.445454545
25 6 9.457142857
25 7 9.48
25 8 9.231578947
25 9 9.171428571
25 10 8.92
25 11 8.866666667
25 12 0
25 13 0
24 1 9.323076923
24 2 9.3125
24 3 9.305263158
24 4 9.2
24 5 9.27826087
24 6 9.228571429
24 7 9.126315789
24 8 8.805263158
24 9 8.735714286
24 10 8.49
24 11 8.385714286
24 12 0
24 13 0
23 1 9.4
23 2 9.2
23 3 9.235294118
23 4 9.180952381
23 5 9.19047619
23 6 9.022222222
23 7 9.053333333
23 8 8.65625
23 9 8.558333333
23 10 8.366666667
23 11 8.328571429
23 12 8.02
23 13 0
22 1 9.05
22 2 9.030769231
22 3 9.033333333
22 4 9.133333333
22 5 9.2
22 6 9.188235294
22 7 9.242857143
22 8 8.976923077
22 9 8.75
22 10 8.585714286
22 11 8.45
22 12 0
22 13 0
21 1 9.036363636
21 2 9.0875
21 3 8.99
21 4 9.019047619
21 5 9.136842105
21 6 9.106666667
21 7 9.066666667
21 8 8.75
21 9 8.6125
21 10 8.516666667
21 11 8.34
21 12 0
21 13 0
20 1 9.357142857
20 2 9.477777778
20 3 9.257142857
20 4 9.2
20 5 9.258823529
20 6 9.216666667
20 7 8.9
20 8 8.18
20 9 0
20 10 0
20 11 0
20 12 0
20 13 0
19 1 9.941176471
19 2 9.92
19 3 9.59047619
19 4 9.5
19 5 9.357142857
19 6 9.288888889
19 7 0
19 8 0
19 9 0
19 10 0
19 11 0
19 12 0
19 13 0
18 1 9.98
18 2 10.10434783
18 3 9.92173913
18 4 9.831578947
18 5 9.728571429
18 6 9.955555556
18 7 0
18 8 0
18 9 0
18 10 0
18 11 0
18 12 0
18 13 0
17 1 10.08181818
17 2 10.216
17 3 10.04166667
17 4 10.02105263
17 5 9.828571429
17 6 9.955555556
17 7 0
17 8 0
17 9 0
17 10 0
17 11 0
17 12 0
17 13 0
16 1 10.36363636
16 2 10.49166667
16 3 10.42608696
16 4 10.44444444
16 5 10.04615385
16 6 10.2
16 7 0
16 8 0
16 9 0
16 10 0
16 11 0
16 12 0
16 13 0
15 1 10.42
15 2 10.4
15 3 10.37142857
15 4 10.475
15 5 10
15 6 10.08571429
15 7 0
15 8 0
15 9 0
15 10 0
15 11 0
15 12 0
15 13 0
14 1 10.03157895
14 2 10.03478261
14 3 10.15238095
14 4 10.2625
14 5 9.927272727
14 6 9.914285714
14 7 0
14 8 0
14 9 0
14 10 0
14 11 0
14 12 0
14 13 0
13 1 9.652631579
13 2 9.634782609
13 3 9.552380952
13 4 9.7875
13 5 9.290909091
13 6 9.228571429
13 7 0
13 8 0
13 9 0
13 10 0
13 11 0
13 12 0
13 13 0
12 1 9.747368421
12 2 9.747826087
12 3 9.761904762
12 4 9.9875
12 5 9.6
12 6 9.657142857
12 7 0
12 8 0
12 9 0
12 10 0
12 11 11.44
12 12 12.1
12 13 12.32
11 1 9.7
11 2 9.709090909
11 3 9.72
11 4 9.946666667
11 5 9.5
11 6 9.571428571
11 7 0
11 8 0
11 9 0
11 10 0
11 11 11.56666667
11 12 12.11428571
11 13 12.3
10 1 9.564705882
10 2 9.59
10 3 9.621052632
10 4 9.728571429
10 5 9.466666667
10 6 9.533333333
10 7 10.04
10 8 0
10 9 11.36666667
10 10 11.37142857
10 11 11.62
10 12 12
10 13 12.1
9 1 9.505882353
9 2 9.6
9 3 9.435294118
9 4 9.583333333
9 5 9.4
9 6 9.68
9 7 10.56666667
9 8 11.8
9 9 11.85
9 10 11.64
9 11 11.81428571
9 12 12
9 13 12.03333333
8 1 9.611111111
8 2 9.682352941
8 3 9.546666667
8 4 9.36
8 5 9.36
8 6 0
8 7 11
8 8 11.8
8 9 11.675
8 10 11.52727273
8 11 11.8
8 12 11.76
8 13 11.7
7 1 9.431578947
7 2 9.529411765
7 3 9.56
7 4 9.36
7 5 9.64
7 6 0
7 7 11.71428571
7 8 12.05714286
7 9 11.74545455
7 10 11.66666667
7 11 11.87368421
7 12 11.61111111
7 13 11.63529412
6 1 9.2
6 2 9.329411765
6 3 9.24
6 4 9.2
6 5 9.975
6 6 10.675
6 7 11.36363636
6 8 11.45
6 9 11.38666667
6 10 11.42105263
6 11 11.60909091
6 12 11.42857143
6 13 11.59
5 1 9.345454545
5 2 9.515789474
5 3 9.541176471
5 4 9.657142857
5 5 10.33333333
5 6 10.95
5 7 11.26666667
5 8 11.425
5 9 11.41111111
5 10 11.24761905
5 11 11.40869565
5 12 11.24545455
5 13 11.27619048
4 1 9.365217391
4 2 9.45
4 3 9.610526316
4 4 9.964705882
4 5 10.5
4 6 11.225
4 7 11.36842105
4 8 11.4
4 9 11.27368421
4 10 11.19047619
4 11 11.28181818
4 12 11.16190476
4 13 11.21818182
3 1 9.454545455
3 2 9.580952381
3 3 9.904761905
3 4 10.27
3 5 10.58947368
3 6 11.23
3 7 11.54545455
3 8 11.71428571
3 9 11.76190476
3 10 11.64347826
3 11 11.6
3 12 11.51428571
3 13 11.42857143
2 1 9.511111111
2 2 9.577777778
2 3 9.831578947
2 4 10.25263158
2 5 10.52
2 6 11.18095238
2 7 11.46956522
2 8 11.76363636
2 9 11.88181818
2 10 11.79130435
2 11 11.67272727
2 12 11.63157895
2 13 11.37777778
1 1 9.6
1 2 9.613333333
1 3 9.882352941
1 4 10.22352941
1 5 10.44705882
1 6 11.41111111
1 7 11.66
1 8 12.18888889
1 9 12.28421053
1 10 12.14
1 11 11.93333333
1 12 11.85333333
1 13 11.32857143
;


proc template;
define statgraph surface;
dynamic range1;
begingraph;
entrytitle 'Yield Data';
rangeattrmap name="yield_map";
range 45-52.24 / rangecolormodel=(darkred);
range 52.25-56.53 / rangecolormodel=(red);
range 56.54-60.82 / rangecolormodel=(yellow);
range 60.83-65.11 / rangecolormodel=(green);
range 65.12-70 / rangecolormodel=(darkgreen);
endrangeattrmap;
rangeattrvar attrvar=yieldvar var=yield attrmap="yield_map";
layout overlay3d / rotate=range1 tilt=90;
surfaceplotparm x=Latitude y=Longitude z=yield / surfacetype=fillgrid
colorresponse=yieldvar name="surface";
continuouslegend "surface";
endlayout;
endgraph;
end;
run;

ods graphics / width=640px height=640px;
proc g3grid data=surface_data out=gridded;
grid Longitude*Latitude=Yield / spline
axis1=1 to 25 by 1
axis2=1 to 13 by 1;
run;
proc sort data=gridded; by Longitude Latitude; run;

%macro test;
%do i=10 %to 360 by 10;
proc sgrender data=gridded template=surface;
dynamic range1="&i";
run;
quit;
%end;
%mend;

%test;

 

 

 

I do not get any output with this code.

Contributor
Posts: 23

Re: Generate output of multiple graphs by changing one variable

[ Edited ]

PS : I am using SAS ondemand for academics

Solution
‎12-11-2016 11:16 PM
Super User
Posts: 1,107

Re: Generate output of multiple graphs by changing one variable

A small change, i just realised that by increment will not work in %do loop. Hence i updated the code as below. I tested this and it is working. Please try and let me know if its working for you



%macro test;
%do i=1 %to 36;
%let j=%eval(&i*10);
proc sgrender data=gridded template=surface;
dynamic range1="&j";
run;
quit;
%end;
%mend;

%test;
Thanks,
Jag
Contributor
Posts: 23

Re: Generate output of multiple graphs by changing one variable

Thanks Jag,

The code now works as expected. Thank you very much for your time and help !!

☑ This topic is SOLVED.

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

Discussion stats
  • 10 replies
  • 264 views
  • 1 like
  • 2 in conversation