LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 7 Dec 2006 15:52:15 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Re: Trying to Understand how the OUTPUT statement works
Comments: cc: SAS_learner <proccontents@GMAIL.COM>

Summary: DATA statement and OUTPUT statement connection #iw-value=1

SAS_learner,

Others have answered your question, but have not made explicit the sysntax or relationship to the DATA statement.

A list of output data sets follows the key word DATA in the DATA statement.

Examples:

data ; * creates one data set with name DATA# where # is sequential to the system. *; data w ; * standard one data set named W *; data w1 w2 w3 ; * creates 3 data sets W1, W2, and W3 *; data _null_ ; * creates no output data sets *;

The OUTPUT statement takes the form

output <optional list of data sets which must be named in DATA statement> ;

Examples:

output ; * writes one record to all data sets implied by the DATA statement *;

output w1 w2 ; * writes one record to just the specified data sets which must be named in the DATA statement *;

/* write the same record twice to all implied data sets */ output ; output ;

/* write 5 records to all implied output data sets only value that changes is X when it is in an implied data set. */ do x = 1 to 5 ; output ; end ;

Examples:

/* writes one record to W with no variables */ data w ; run ;

/* writes header to W with no variables and no observations */ data w ; stop ; run ;

/* writes header to W (one variable named in header) */ data w ; x = 1 ; stop; output ; run ;

/* writes one record with no variables to W */ data w ; x = 1 ; output ; stop ; drop x ; run ;

/* w1 has 2 record with two variables - x and y w2 has 2 records with one variable - x w3 has 2 records with one variable - y */ data w1 w2 ( drop = y ) w3 ( drop = x ) ; x = 1 ; if x = 1 then output w1 w3 ; if not y then output w2 ; output ; run ;

/* create data set Q with one variable V having values of 5 variables in one record data set w */ data w ; retain x1 1 x2 2 x3 3 x4 4 x5 5 ; run ; data q ( keep = v ) ; set w ; array x (5) ; do i = 1 to dim(x) ; v = x[i] ; output ; end ; run ;

/* create data set Q2 matching W in previous example */ data q2 ( keep = x1-x5 ) ; array x (5) ; do i = 1 to 5 until ( eof ) ; set q end = eof ; x[i] = v ; end ; run ;

I hope this gives you some more to think about OUTPUT.

Ian Whitlock


Back to: Top of message | Previous page | Main SAS-L page