-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrough.sas
497 lines (429 loc) · 12 KB
/
rough.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
%let path = H:\GitHub\srosanba\sas-consort-experimental;
%let width = 8;
%let height = 6;
%let textsize = 9;
*--------------------------------------------------------------------------------;
*---------- start with rough row/col layout ----------;
*--------------------------------------------------------------------------------;
proc import
file = "&path\rough.xlsx"
out = rough00
dbms = xlsx
replace
;
sheet = "rowCol";
run;
*--- largest row/col values ---;
proc sql noprint;
select max(row)
into :maxrow
from rough00
where row = round(row)
;
%let maxrow=&maxrow;
%put &=maxrow;
select max(col)
into :maxcol
from rough00
where col = round(col)
;
%let maxcol=&maxcol;
%put &=maxcol;
quit;
*--- position each row/col as a percent of the max ---;
data rough10;
set rough00;
roughx = 100 * (col/(&maxcol+1));
roughy = 100 * (row/(&maxrow+1));
run;
*--- build a 0-100 canvas ---;
data dummy10;
dummyx = 0;
dummyy = 0;
output;
dummyx = 100;
dummyy = 100;
output;
run;
data plot10;
set rough10 dummy10;
run;
*--- the plotting business ---;
ods graphics /
reset=all
outputfmt=png
width=&width.in
height=&height.in
imagename="rough"
;
ods listing
gpath="&path/img"
;
proc template;
define statgraph outfile;
begingraph / pad=0.01in;
layout overlay /
xaxisopts=(
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &width))
)
yaxisopts=(
reverse=true
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &height))
)
;
*--- use dummy values to force desired dimensions ---;
ScatterPlot X=dummyx Y=dummyy /
subpixel=off primary=true
LegendLabel="dummyy" NAME="SCATTER"
;
*--- write text and draw box around it, saving box dimensions in CSV file ---;
TextPlot X=roughx Y=roughy text=roughText /
LegendLabel="texty" NAME="TEXT"
position=center splitpolicy=splitalways SplitChar="~"
Display=(Outline) textattrs=(size=&textsize)
OutFile="&path/rough.csv" OutID=boxId
;
endlayout;
endgraph;
end;
run;
proc sgrender data=plot10 template=outfile;
run;
*--------------------------------------------------------------------------------;
*---------- use rough coordinates to refine y positioning ----------;
*--------------------------------------------------------------------------------;
proc import
file = "&path/rough.csv"
out = outfile00 (keep=outid data: rename=(outid=boxId))
dbms = csv
replace
;
run;
data rough20;
merge rough10 outfile00;
by boxId;
run;
*--- focus on integer row values ---;
proc sql noprint;
select distinct row
into :rows separated by ' '
from rough20
where row = round(row)
;
%put &=rows;
quit;
*--- maximum space used in each row ---;
proc sql noprint;
create table maxdataheight as
select row, max(dataheight) as maxdataheight
from rough20
where row in (&rows)
group by row
;
select sum(maxdataheight) as sumheight
into :sumheight
from maxdataheight
;
%put &=sumheight;
quit;
proc sort data=rough20 out=rough25;
by row col;
run;
*--- calculate integer row positions ---;
data row10;
set rough25;
by row;
if first.row and row = round(row);
retain bettery usedheight 0;
gapheight = (100-&sumheight)/(&maxrow);
if row = 1 then do;
bettery = gapheight/2 + dataheight/2;
usedheight = usedheight + gapheight/2 + dataheight;
end;
else do;
bettery = usedheight + gapheight + dataheight/2;
usedheight = usedheight + gapheight + dataheight;
end;
keep gapheight row bettery;
run;
*--- use integer positions to interpolate non-integer positions ---;
proc transpose data=row10 out=trow10 prefix=row;
by gapheight;
id row;
var bettery;
run;
data rough30;
set rough25;
if _N_ = 1 then
set trow10;
array br {&maxrow} row1-row&maxrow;
do i = 1 to &maxrow;
if row = i then
bettery = br[i];
end;
if missing(bettery) then do;
prev = floor(row);
next = ceil(row);
bettery = (row-prev)*br[prev] + (next-row)*br[next];
end;
run;
data plot30;
set rough30 dummy10;
run;
*--- the plotting business ---;
ods graphics /
reset=all
outputfmt=png
width=&width.in
height=&height.in
imagename="bettery"
;
ods listing
gpath="&path/img"
;
proc template;
define statgraph bettery;
begingraph / pad=0.01in;
layout overlay /
xaxisopts=(
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &width))
)
yaxisopts=(
reverse=true
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &height))
)
;
*--- use dummy values to force desired dimensions ---;
ScatterPlot X=dummyx Y=dummyy /
subpixel=off primary=true
LegendLabel="dummyy" NAME="SCATTER"
;
*--- write text and draw box around it, saving box dimensions in CSV file ---;
TextPlot X=roughx Y=bettery text=roughText /
LegendLabel="texty" NAME="TEXT"
position=center splitpolicy=splitalways SplitChar="~"
Display=(Outline) textattrs=(size=&textsize)
;
endlayout;
endgraph;
end;
run;
proc sgrender data=plot30 template=bettery;
run;
*--------------------------------------------------------------------------------;
*---------- use rough coordinates to refine x positioning ----------;
*--------------------------------------------------------------------------------;
*--- focus on integer col values ---;
proc sql noprint;
select distinct col
into :cols separated by ' '
from rough20
where col = round(col)
;
%put &=cols;
quit;
*--- maximum spaces used in each col ---;
proc sql noprint;
create table maxdatawidth as
select col, max(datawidth) as maxdatawidth
from rough20
where col in (&cols)
group by col
;
select sum(maxdatawidth) as sumwidth
into :sumwidth
from maxdatawidth
;
%put &=sumwidth;
quit;
proc sort data=rough30 out=rough35;
by col row;
run;
*--- calculate integer col positions ---;
data col10;
set rough35;
by col;
if first.col and col = round(col);
retain bettery usedwidth 0;
gapwidth = (100-&sumwidth)/(&maxcol);
if col = 1 then do;
betterx = gapwidth/2 + datawidth/2;
usedwidth = usedwidth + gapwidth/2 + datawidth;
end;
else do;
betterx = usedwidth + gapwidth + datawidth/2;
usedwidth = usedwidth + gapwidth + datawidth;
end;
keep gapwidth col betterx;
run;
*--- use integer positions to interpolate non-integer positions ---;
proc transpose data=col10 out=tcol10 prefix=col;
by gapwidth;
id col;
var betterx;
run;
%let bcdim = %eval(&maxcol+1);
%put &=bcdim;
data rough40;
set rough35;
if _N_ = 1 then
set tcol10;
zero = 0 - gapwidth/2 - &sumwidth/&maxcol/2;
hundo = 100 + gapwidth/2 + &sumwidth/&maxcol/2;
array bc {0:&bcdim} zero col1-col&maxcol hundo;
do i = 0 to &bcdim;
if col = i then
betterx = bc[i];
end;
if missing(betterx) then do;
prev = floor(col);
next = ceil(col);
betterx = (col-prev)*bc[next] + (next-col)*bc[prev];
end;
run;
data plot40;
set rough40 dummy10;
run;
*--- the plotting business ---;
ods graphics /
reset=all
outputfmt=png
width=&width.in
height=&height.in
imagename="betterx"
;
ods listing
gpath="&path/img"
;
proc template;
define statgraph betterx;
begingraph / pad=0.01in;
layout overlay /
xaxisopts=(
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &width))
)
yaxisopts=(
reverse=true
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &height))
)
;
*--- use dummy values to force desired dimensions ---;
ScatterPlot X=dummyx Y=dummyy /
subpixel=off primary=true
LegendLabel="dummyy" NAME="SCATTER"
;
*--- write text and draw box around it, saving box dimensions in CSV file ---;
TextPlot X=betterx Y=bettery text=roughText /
LegendLabel="texty" NAME="TEXT"
position=center splitpolicy=splitalways SplitChar="~"
Display=(Outline) textattrs=(size=&textsize)
;
endlayout;
endgraph;
end;
run;
proc sgrender data=plot40 template=betterx;
run;
*--------------------------------------------------------------------------------;
*---------- final adjustments ----------;
*--------------------------------------------------------------------------------;
proc sort data=rough40 out=final;
by boxId;
run;
*--- previous work utilizes CENTER positioning for each of calculations ---;
*--- need to modify to fit into BOTTOM positioning paradigm of helper macros ---;
data final;
set final;
finalx = round(betterx, .01);
finaly = round(bettery - dataheight/2, .01);
finalwidth = round(datawidth, .01);
finalheight = round(dataheight, .01);
run;
data plotfinal;
set final dummy10;
run;
*--- extraneous final look ---;
ods graphics /
reset=all
outputfmt=png
width=&width.in
height=&height.in
imagename="final"
;
ods listing
gpath="&path/img"
;
proc template;
define statgraph final;
begingraph / pad=0.01in;
layout overlay /
xaxisopts=(
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &width))
)
yaxisopts=(
reverse=true
display=none
offsetmin=0 offsetmax=0
type=linear
linearopts=(tickvaluelist=(0 &height))
)
;
*--- use dummy values to force desired dimensions ---;
ScatterPlot X=dummyx Y=dummyy /
subpixel=off primary=true
LegendLabel="dummyy" NAME="SCATTER"
;
*--- write text and draw box around it, saving box dimensions in CSV file ---;
TextPlot X=finalx Y=finaly text=roughText /
LegendLabel="texty" NAME="TEXT"
position=bottom splitpolicy=splitalways SplitChar="~"
Display=(Outline) textattrs=(size=&textsize)
;
endlayout;
endgraph;
end;
run;
proc sgrender data=plotfinal template=final;
run;
*--------------------------------------------------------------------------------;
*---------- copy from putstring to kick-start helper macro approach ----------;
*--------------------------------------------------------------------------------;
data putstring;
set final;
format boxId 2. finalx finaly finalwidth finalheight 6.2;
length putstring $100;
putstring = cat
(put(boxId,z2.)
,", "
,put(finalx,6.2)
,","
,put(finaly,6.2)
,", "
,put(finalwidth,6.2)
,","
,put(finalheight,6.2)
);
put putstring;
keep putstring;
run;