Previous Page | Next Page

Hash and Hash Iterator Object Language Elements

OUTPUT Method



Creates one or more data sets each of which contain the data in the hash object.
Applies to: Hash object

Syntax
Arguments
Details
Examples
See Also

Syntax

rc=object.OUTPUT(DATASET: 'dataset-1 <(datasetoption)>' <..., DATASET: 'dataset-n'>('datasetoption<(datasetoption)>');


Arguments

rc

specifies whether the method succeeded or failed.

A return code of zero indicates success; a non-zero value indicates failure. If you do not supply a return code variable for the method call and the method fails, then an appropriate error message is written to the log.

object

specifies the name of the hash object.

DATASET: 'dataset'

specifies the name of the output data set.

The name of the SAS data set can be a character literal or character variable. The data set name can also be enclosed in double quotation marks. When specifying the name of the output data set, you can use SAS data set options in the DATASET argument tag. Macro variables must be enclosed in double quotation marks.

datasetoption

specifies a data set option.

For complete information about how to specify data set options, see Syntax.


Details

Hash object keys are not automatically stored as part of the output data set. The keys must be defined as data items by using the DEFINEDATA method to be included in the output data set.

If you use the ordered: 'yes' or ordered: 'ascending' argument tag in the DECLARE statement or _NEW_ operator when you instantiate the hash object, then the data items are written to the data set in ascending key-value order. If you use the ordered: 'descending' argument tag in the DECLARE statement or _NEW_ operator when you instantiate the hash object, then the data items are written to the data set in descending key-value order. If you do not use the ordered argument tag, the order is undefined.

When specifying the name of the output data set, you can use SAS data set options in the DATASET argument tag. Data set options specify actions that apply only to the SAS data set with which they appear. They let you perform the following operations:

The following example uses the WHERE data set option to select specific data for the output data set named OUT:
data x;
 do i = 1 to 20;
   output;
 end;
run;
 
/* Using the WHERE option. */
data _null_;
  length i 8;
  dcl hash h();
  h.definekey(all: 'y');
  h.definedone();
  h.output(dataset: 'out (where =( i < 8))');
run;

The following example uses the RENAME data set option to rename the variable J to K for the output data set named OUT:

data x;
 do i = 1 to 20;
   output;
 end;
run;

/* Using the RENAME option. */
data _null_;
  length i j 8;
  dcl hash h();
  h.definekey(all: 'y');
  h.definedone();
  h.output(dataset: 'out (rename =(j=k))');
run; 

For a list of data set options, see Data Set Options by Category.

Note:   When you use the OUTPUT method to create a data set, the hash object is not part of the output data set. In the following example, the H2 hash object will be omitted from the output data set.

data _null_;
   length k 8;
   length d $10;
   declare hash h2();
   declare hash h(ordered: 'y');
   h.defineKey('k');
   h.defineData('k', 'd', 'h2');
   h.defineDone();
   k = 99;
   d = 'abc';
   h.add();
   k = 199;
   d = 'def';
   h.add();
   h.output(dataset:'work.x');
run;

  [cautionend]


Examples

Using the data set ASTRO that contains astronomical data, the following code creates a hash object with the Messier (OBJ) objects sorted in ascending order by their right-ascension (RA) values and uses the OUTPUT method to save the data to a data set.

data astro;
input obj $1-4 ra $6-12 dec $14-19;
datalines;
 M31 00 42.7 +41 16
 M71 19 53.8 +18 47
 M51 13 29.9 +47 12
 M98 12 13.8 +14 54
 M13 16 41.7 +36 28
 M39 21 32.2 +48 26
 M81 09 55.6 +69 04
M100 12 22.9 +15 49
 M41 06 46.0 -20 44
 M44 08 40.1 +19 59
 M10 16 57.1 -04 06
 M57 18 53.6 +33 02
  M3 13 42.2 +28 23
 M22 18 36.4 -23 54
 M23 17 56.8 -19 01
 M49 12 29.8 +08 00
 M68 12 39.5 -26 45
 M17 18 20.8 -16 11
 M14 17 37.6 -03 15
 M29 20 23.9 +38 32
 M34 02 42.0 +42 47
 M82 09 55.8 +69 41
 M59 12 42.0 +11 39
 M74 01 36.7 +15 47
 M25 18 31.6 -19 15
;
run;

data _null_;
   if _N_ = 1 then do;
      length obj $10;
      length ra $10;
      length dec $10;
      /* Read ASTRO data set as ordered */
   declare hash h(hashexp: 4, dataset:"work.astro", ordered: 'yes');
      /* Define variables RA and OBJ as key and data for hash object */
      h.defineKey('ra');
      h.defineData('ra', 'obj');
      h.defineDone();
      /* avoid uninitialized variable notes */
      call missing(ra, obj);
end;
/* Create output data set from hash object */
rc = h.output(dataset: 'work.out');
run;

proc print data=work.out;
   var ra obj;
   title 'Messier Objects Sorted by Right-Ascension Values';
run;

Messier Objects Sorted by Right-Ascension Values

               Messier Objects Sorted by Right-Ascension Values              1

                            Obs      ra       obj

                              1    00 42.7    M31 
                              2    01 36.7    M74 
                              3    02 42.0    M34 
                              4    06 46.0    M41 
                              5    08 40.1    M44 
                              6    09 55.6    M81 
                              7    09 55.8    M82 
                              8    12 13.8    M98 
                              9    12 22.9    M100
                             10    12 29.8    M49 
                             11    12 39.5    M68 
                             12    12 42.0    M59 
                             13    13 29.9    M51 
                             14    13 42.2    M3  
                             15    16 41.7    M13 
                             16    16 57.1    M10 
                             17    17 37.6    M14 
                             18    17 56.8    M23 
                             19    18 20.8    M17 
                             20    18 31.6    M25 
                             21    18 36.4    M22 
                             22    18 53.6    M57 
                             23    19 53.8    M71 
                             24    20 23.9    M29 
                             25    21 32.2    M39 

See Also

Methods:

DEFINEDATA Method

Operators:

_NEW_ Operator, Hash or Hash Iterator Object

Statements:

DECLARE Statement, Hash and Hash Iterator Objects

Saving Hash Object Data in a Data Set in SAS Language Reference: Concepts

Previous Page | Next Page | Top of Page