Data Processing and I/O in PROC IML

 /****************************************************************/
 /*            S A S   S A M P L E   L I B R A R Y               */
 /*                                                              */
 /*    NAME: DATADEMO                                            */
 /*   TITLE: Data Processing and I/O in PROC IML                 */
 /* PRODUCT: IML                                                 */
 /*  SYSTEM: ALL                                                 */
 /*    KEYS: MATRIX DATMAN                                       */
 /*   PROCS: IML                                                 */
 /*    DATA:                                                     */
 /*                                                              */
 /* SUPPORT: LWB                         UPDATE:  NOV1989        */
 /*     REF:                                                     */
 /*    MISC: THIS PROGRAM WILL CREATE AN EXTERNAL FILE.          */
 /*                                                              */
 /****************************************************************/

 /*--create filename for class data--*/
%macro filedef;
  %if &sysscp=OS
  %then %str(filename classf '&class' recfm=vb
                      lrecl=300 blksize=15825;);

  %else %if &sysscp=CMS
        %then  %str(filename classf 'class dat';);

        %else  /* other hosts */
               %str(filename classf 'class.dat';);
%mend ;
%filedef

 /*--create external file for class information--*/
data _null_;
   file classf;
   input name $ sex $ age height weight;
   put name $ sex $ age height weight;
   cards;
JOYCE   F 11 51.3 50.5
THOMAS  M 11 57.5 85.0
JAMES   M 12 57.3 83.0
JANE    F 12 59.8 84.5
JOHN    M 12 59.0 99.5
LOUISE  F 12 56.3 77.0
ROBERT  M 12 64.8 128.0
ALICE   F 13 56.5 84.0
BARBARA F 13 65.3 98.0
JEFFREY M 13 62.5 84.0
CAROL   F 14 62.8 102.5
HENRY   M 14 63.5 102.5
ALFRED  M 14 69.0 112.5
JUDY    F 14 64.3 90.0
JANET   F 15 62.5 112.5
MARY    F 15 66.5 112.0
RONALD  M 15 67.0 133.0
WILLIAM M 15 66.5 112.0
PHILIP  M 16 72.0 150.0
;

proc iml;

 /*--read in data file for class and create class data set--*/
name="12345678"; sex="m";
create class var{name sex age height weight};

infile classf;

do data;
   input name $ sex $ age height weight;
   append;
   end;
close class;
closefile classf;

 /*--basic listing--*/
use class;
show datasets;
show contents;
list all;
list;
list point 5;
list next;
list next;
list;
list point {2 4 9};
p={2 4 9};
print p;
list point p;
list var{name sex};
list point p var {name age};
v={name sex age};
list var v;
list all var v where(sex="M");
list all where(age>13);

 /*--find--*/
find all where(age>13) into p;
print p;
list point p;
find all where(age>14) into q;
print p q;
list point q;

 /*--read---*/
read point q;
show names;
print name age height weight;
read point 8;
print name age height weight;
read all var{name height} where(height>62);
print name height;

create new var{name height};
append;
close new class;

 /*--where clause--*/
use class var{name};
list all;
list all where(name=:"J");
list all where(name=:"JA");
list all where(name=*"LOIS");
list all where(name=*"PHILLIP");
list all where(name?"AL");
list all where(name={alfred carol judy});
list all where(name=*{jon jan });
close class;

 /*--replace--*/
edit class;
list all where(name="JOHN");
age=13; replace point 5 var {age};
list point 5;
read point 5;
age=18; height=62.; weight=99;
append;
list point 20;
close class;

 /*--sort--*/
sort class out=class2 by age;

use class2; list all;

 /*--index--*/
index name;
list all where(name=:"JO");
list next;
list next;
close class2;

 /*--summary--*/
use class;
summary var{height weight} class{age} stat{mean std};
close class;