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 (June 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 8 Jun 2006 09:19:54 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: How SAS Executes this Code?

On Thu, 8 Jun 2006 00:45:10 -0700, Jaggie <jagadishkr@GMAIL.COM> wrote:

>"Howard Schreier <hs AT dc-sug DOT org>" wrote: >> On Tue, 6 Jun 2006 06:56:27 -0400, Richard A. DeVenezia >> <rdevenezia@WILDBLUE.NET> wrote: >> >> >Jaggie wrote: >> >> Hi All, >> >> >> >> I have a small code which is haunting me. Code is very simple but >> >> unable to understand how SAS executes this code. >> >> >> >> data x; >> >> input Price; >> >> Cards; >> >> 1.08 >> >> 1.10 >> >> 1.14 >> >> 1.23 >> >> 1.29 >> >> ; >> >> run; >> >> >> >> data y; >> >> do i=1 to 3; >> >> set x; >> >> end; >> >> run; >> >> >> >> Data set X has 5 obs. I tried with Put _ALL_ statement and found below >> >> observations, >> >> >> >> If I use do loop with , >> >> i =1 to 1 then it outputs 5 obs to dataset Y. >> >> i=1 to 2 then 2 obs >> >> i=1 to 3 then 1 obs >> >> i=1 to 4 then 1 obs >> >> i=1 to 5 then also 1 obs >> >> i=1 to 6 or above then 0 obs. >> >> >> >> Please let me know how SAS executes this code. Especially when we use >> >> set statement within do loops. >> >> >> >> Thanks, >> >> Jagadish >> > >> > >> >- Each time the SET statement is reached a row is read from Table x >> >- Each time the flow of control reaches the bottom of the Step, a row is >> >written via an implied "OUTPUT". (If you use an explicit OUTPUT statement >> >anywhere in the STEP the implied output does not occur) >> >> and >> >> - If the SET statement is reached but there are no more unread rows, >> execution ceases. >> >> > >> >Let NOBS be 5 and MAX_I be the top of your loop -- thus in your code, the >> >bottom of the Step is reached every MAX_I'th row and you get >> >floor(NOBS/MAX_I) rows output. >> > >> >There are far better discussions (conference papers, online help, books by >> >users, etc...) concerning the operation of the DATA Step than this short >> >answer. Be sure to check them out. >> > >> >-- >> >Richard A. DeVenezia >> >http://www.devenezia.com/ > >Then what is the difference between below codes. > >data y; >do i=1 to 5; > set x; >end; >run; > >In above dataset if x has 5 obs, then out put dataset has 1 obs. > >data y; > set x; > set x; > set x; > set x; > set x; >run; > >I think in the above code, 5 copies of dataset x are created and >whenever set is encountered observation in its corresponding dataset >moves to next obs. But all the obs from last set x statement are out >put. Am I right?

That's pretty close. I think it's a bit more accurate to say that the mechanism for reading X (buffers, pointers, etc.) is set up 5 times and that the 5 instances function independently.

There is also

set x x x x x ;

which is quite different.

> >Thanks, >Jagadish


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