Options

options mcompilenote=ALL symbolgen mprint;

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

208  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
208! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
209
210 options mcompilenote=ALL symbolgen mprint;
211
212 ods html5 (id=saspy_internal) close;ods listing;

213

Libraries

libname pa "/folders/myfolders/libToPlot1";
libname pb "/folders/myfolders/libToPlot2";
libname pc "/folders/myfolders/libToPlot3";

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

215  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
215! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
216
217 libname pa "/folders/myfolders/libToPlot1";
NOTE: Libref PA refers to the same physical library as ABC.
NOTE: Libref PA was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/libToPlot1
218 libname pb "/folders/myfolders/libToPlot2";
NOTE: Libref PB refers to the same physical library as BC.
NOTE: Libref PB was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/libToPlot2
219 libname pc "/folders/myfolders/libToPlot3";
NOTE: Libref PC refers to the same physical library as BC.
NOTE: Libref PC was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/libToPlot3
220
221 ods html5 (id=saspy_internal) close;ods listing;

222

Library contents

/*concatenate the libraries*/

libname abc (pa, pb, pc);

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

224  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
224! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
225
226 /*concatenate the libraries*/
227
228 libname abc (pa, pb, pc);
NOTE: Libref ABC was successfully assigned as follows:
Levels: 3
Engine(1): V9
Physical Name(1): /folders/myfolders/libToPlot1
Engine(2): V9
Physical Name(2): /folders/myfolders/libToPlot2
Engine(3): V9
Physical Name(3): /folders/myfolders/libToPlot3
229
230 ods html5 (id=saspy_internal) close;ods listing;

231
proc contents data=abc._all_ nods;
run;
<!DOCTYPE html> SAS Output

The CONTENTS Procedure

Directory
Libref ABC
Levels 3
Level 1
Engine V9
Physical Name /folders/myfolders/libToPlot1
Filename /folders/myfolders/libToPlot1
Inode Number 968
Access Permission rwxrwx—
Owner Name root
File Size 4KB
File Size (bytes) 4096
Level 2
Engine V9
Physical Name /folders/myfolders/libToPlot2
Filename /folders/myfolders/libToPlot2
Inode Number 969
Access Permission rwxrwx—
Owner Name root
File Size 4KB
File Size (bytes) 4096
Level 3
Engine V9
Physical Name /folders/myfolders/libToPlot3
Filename /folders/myfolders/libToPlot3
Inode Number 970
Access Permission rwxrwx—
Owner Name root
File Size 4KB
File Size (bytes) 4096
# Name Member Type Level File Size Last Modified
1 BMIMEN DATA 2 128KB 07/09/2020 15:33:34
2 CLASS DATA 1 128KB 07/09/2020 15:08:43
3 FISH DATA 1 128KB 07/09/2020 15:28:44
4 GAS DATA 2 128KB 07/09/2020 15:35:44
5 GNP DATA 1 128KB 07/09/2020 15:29:45
6 IRIS DATA 3 128KB 07/09/2020 15:36:46
7 LAKE DATA 3 128KB 07/09/2020 15:38:03
8 ORSALES DATA 2 192KB 07/09/2020 19:36:38
9 SHOES DATA 3 128KB 07/09/2020 15:40:42

A macro for plotting box plots for each numeric variable in a data set

/* One macro calls another macro */

%macro hbox_for_a_df(df);

    %local i;


    %let dfn=%scan(&df, -1);
    

data &dfn;

    set &df;
    
    keep _numeric_;
run;


    %let dfn=%upcase(&dfn);


data _null_;
       
    set sashelp.vcolumn end=final;

    where libname="WORK" and memname="&dfn";
        
    call symputx('col'||left(_n_), name);
      
    if final then call symputx('totalcol', _n_);
      
run;
   
   
   
%do i=1 %to &totalcol;

    ods graphics on/noborder;
  
    proc sgplot data=&dfn;
       
        hbox &&col&i;
            
        title "Boxplot for %upcase(&&col&i) from data set %upcase(&dfn)";
    
    run;
    
    title;
    
    ods graphics off;

%end;
   
   
%mend ;

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

241  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
241! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
242
243 /* One macro calls another macro */
244
245 %macro hbox_for_a_df(df);
246
247 %local i;
248
249
250 %let dfn=%scan(&df, -1);
251
252
253 data &dfn;
254
255 set &df;
256
257 keep _numeric_;
258 run;
259
260
261 %let dfn=%upcase(&dfn);
262
263
264 data _null_;
265
266 set sashelp.vcolumn end=final;
267
268 where libname="WORK" and memname="&dfn";
269
270 call symputx('col'||left(_n_), name);
271
272 if final then call symputx('totalcol', _n_);
273
274 run;
275
276
277
278 %do i=1 %to &totalcol;
279
280 ods graphics on/noborder;
281
282 proc sgplot data=&dfn;
283
284 hbox &&col&i;
285
286 title "Boxplot for %upcase(&&col&i) from data set %upcase(&dfn)";
287
288 run;
289
290 title;
291
292 ods graphics off;
293
294 %end;
295
296
297 %mend ;
NOTE: The macro HBOX_FOR_A_DF completed compilation without errors.
34 instructions 1160 bytes.
298
299 ods html5 (id=saspy_internal) close;ods listing;

300

Call the macro

%hbox_for_a_df(pc.iris)
<!DOCTYPE html> SAS Output

The SGPlot Procedure


svgtitle The SGPlot Procedure 20 25 30 35 40 45 Sepal Width (mm) Boxplot for SEPALWIDTH from data set IRIS

svgtitle The SGPlot Procedure 10 20 30 40 50 60 70 Petal Length (mm) Boxplot for PETALLENGTH from data set IRIS

svgtitle The SGPlot Procedure 0 5 10 15 20 25 Petal Width (mm) Boxplot for PETALWIDTH from data set IRIS

A macro for producing box plots for each numeric variable of each data set in a library

/*This macro calls the previous macro (hbox_for_a_df) and uses a do `while loop` to traverse through a list of data sets.*/

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

309  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
309! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
310
311 /*This macro calls the previous macro (hbox_for_a_df) and uses a do `while loop` to traverse through a list of data sets.*/
312
313 ods html5 (id=saspy_internal) close;ods listing;

314
%macro hbox_for_each_df_in_a_lib(lib=x);

    %local i lib;
    

    %let lib=%upcase(&lib);
  

    proc sql noprint;
    
       select cats("&lib..", memname)
       
          into :ds_name_list separated by ' '
          
        from dictionary.tables
        
        where libname="&lib";
    quit;


    %let i=1;
   
   
    data _null_;

        %do %while (%scan(&ds_name_list, &i, %str( )) ne ); /*scan the ds_name_list delimited by a space: %str() */

           %let next_ds_name = %scan(&ds_name_list, &i, %str( ));
       
           %hbox_for_a_df(&next_ds_name)
       
           %let i = %eval(&i + 1);
   
        %end;

    run;
    
    
%mend;

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

316  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
316! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
317
318 %macro hbox_for_each_df_in_a_lib(lib=x);
319
320 %local i lib;
321
322
323 %let lib=%upcase(&lib);
324
325
326 proc sql noprint;
327
328 select cats("&lib..", memname)
329
330 into :ds_name_list separated by ' '
331
332 from dictionary.tables
333
334 where libname="&lib";
335 quit;
336
337
338 %let i=1;
339
340
341 data _null_;
342
343 %do %while (%scan(&ds_name_list, &i, %str( )) ne ); /*scan the ds_name_list delimited by a space: %str() */
344
345 %let next_ds_name = %scan(&ds_name_list, &i, %str( ));
346
347 %hbox_for_a_df(&next_ds_name)
348
349 %let i = %eval(&i + 1);
350
351 %end;
352
353 run;
354
355
356 %mend;
NOTE: The macro HBOX_FOR_EACH_DF_IN_A_LIB completed compilation without errors.
47 instructions 1216 bytes.
357
358 ods html5 (id=saspy_internal) close;ods listing;

359

Call the macro on a library

%hbox_for_each_df_in_a_lib(lib=pa)
<!DOCTYPE html> SAS Output

The SGPlot Procedure


svgtitle The SGPlot Procedure 50 55 60 65 70 Height Boxplot for HEIGHT from data set CLASS

svgtitle The SGPlot Procedure 60 80 100 120 140 Weight Boxplot for WEIGHT from data set CLASS

svgtitle The SGPlot Procedure 0 500 1000 1500 Weight Boxplot for WEIGHT from data set FISH

svgtitle The SGPlot Procedure 10 20 30 40 50 60 Length1 Boxplot for LENGTH1 from data set FISH

svgtitle The SGPlot Procedure 20 40 60 Length2 Boxplot for LENGTH2 from data set FISH

svgtitle The SGPlot Procedure 20 40 60 Length3 Boxplot for LENGTH3 from data set FISH

svgtitle The SGPlot Procedure 5 10 15 20 Height Boxplot for HEIGHT from data set FISH

svgtitle The SGPlot Procedure 2 4 6 8 Width Boxplot for WIDTH from data set FISH

svgtitle The SGPlot Procedure 1960 1965 1970 1975 1980 1985 1990 1995 DATE Boxplot for DATE from data set GNP

svgtitle The SGPlot Procedure 1000 2000 3000 4000 5000 gross national product ($billions) Boxplot for GNP from data set GNP

svgtitle The SGPlot Procedure 1000 2000 3000 4000 personal consumption expenditures Boxplot for CONSUMP from data set GNP

svgtitle The SGPlot Procedure 200 400 600 800 gross private domestic investment Boxplot for INVEST from data set GNP

svgtitle The SGPlot Procedure -100 -50 0 50 net exports of goods and services Boxplot for EXPORTS from data set GNP

svgtitle The SGPlot Procedure 200 400 600 800 1000 1200 govt purchases of goods and services Boxplot for GOVT from data set GNP

Produce box plots for each numeric variable of each data set in a library or multiple libraries

Call the macro on combined libraries

libname bc (pb, pc);

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

368  ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
368! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
369
370 libname bc (pb, pc);
NOTE: Libref BC was successfully assigned as follows:
Levels: 2
Engine(1): V9
Physical Name(1): /folders/myfolders/libToPlot2
Engine(2): V9
Physical Name(2): /folders/myfolders/libToPlot3
371
372 ods html5 (id=saspy_internal) close;ods listing;

373
%hbox_for_each_df_in_a_lib(lib=bc)
<!DOCTYPE html> SAS Output

The SGPlot Procedure


svgtitle The SGPlot Procedure 10 20 30 40 50 60 BMI Boxplot for BMI from data set BMIMEN

svgtitle The SGPlot Procedure 7.5 10.0 12.5 15.0 17.5 Compression Ratio Boxplot for CPRATIO from data set GAS

svgtitle The SGPlot Procedure 0.6 0.8 1.0 1.2 Equivalence Ratio Boxplot for EQRATIO from data set GAS

svgtitle The SGPlot Procedure 0 2 4 6 Nitrogen Oxide Boxplot for NOX from data set GAS

svgtitle The SGPlot Procedure 40 50 60 70 80 Sepal Length (mm) Boxplot for SEPALLENGTH from data set IRIS

svgtitle The SGPlot Procedure 20 25 30 35 40 45 Sepal Width (mm) Boxplot for SEPALWIDTH from data set IRIS

svgtitle The SGPlot Procedure 10 20 30 40 50 60 70 Petal Length (mm) Boxplot for PETALLENGTH from data set IRIS

svgtitle The SGPlot Procedure 0 5 10 15 20 25 Petal Width (mm) Boxplot for PETALWIDTH from data set IRIS

svgtitle The SGPlot Procedure 0 2 4 6 8 10 Width Boxplot for WIDTH from data set LAKE

svgtitle The SGPlot Procedure 0 2 4 6 Length Boxplot for LENGTH from data set LAKE

svgtitle The SGPlot Procedure -30 -20 -10 0 Depth Boxplot for DEPTH from data set LAKE

svgtitle The SGPlot Procedure 1999.0 1999.5 2000.0 2000.5 2001.0 2001.5 2002.0 Year Boxplot for YEAR from data set ORSALES

svgtitle The SGPlot Procedure 0 2000 4000 6000 8000 Number of Items Boxplot for QUANTITY from data set ORSALES

svgtitle The SGPlot Procedure 0 100000 200000 300000 400000 500000 Profit in USD Boxplot for PROFIT from data set ORSALES

svgtitle The SGPlot Procedure 0 200000 400000 600000 800000 1000000 1200000 Total Retail Price in USD Boxplot for TOTAL_RETAIL_PRICE from data set ORSALES

svgtitle The SGPlot Procedure 0 10 20 30 40 Number of Stores Boxplot for STORES from data set SHOES

svgtitle The SGPlot Procedure $0 $250,000 $500,000 $750,000 $1,000,000 $1,250,000 Total Sales Boxplot for SALES from data set SHOES

svgtitle The SGPlot Procedure $0 $500,000 $1,000,000 $1,500,000 $2,000,000 $2,500,000 $3,000,000 Total Inventory Boxplot for INVENTORY from data set SHOES

svgtitle The SGPlot Procedure $0 $10,000 $20,000 $30,000 $40,000 $50,000 $60,000 Total Returns Boxplot for RETURNS from data set SHOES