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 (February 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 27 Feb 2008 06:25:50 -0800
Reply-To:     NM <neerav.monga@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         NM <neerav.monga@GMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: null dataset testing in macro
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

Hi Paul:

Thank you very much for the detailed explanation, that makes total sense to me! It's great to have this listserv to help when people get stuck on these types of issues. I don't normally encounter null data, so I wasn't sure how to handle it.

Cheers!

NM

On Feb 27, 1:24 am, sash...@BELLSOUTH.NET (Paul Dorfman) wrote: > NM, > > The fact that the data set DATA has 0 observations does NOT mean that your step > > data temp; > set data; > call symput ('nulldata',_n_); > run; > > will assign anything to macro variable NULLDATA, because CALL SYMPUT statement will never be executed. The fundamental rule is that a DATA step stops immediately if its SET statement attempts to read from an empty buffer -- and for an data set, it is empty to begin with. So by the time you are testing the value of macro variable NULLDATA, the latter simply does not exist, hence the error. > > Now let us fancy that DATA does have (potentially quite a few) records and reexamine your DATA step again. If DATA has 1 million rows then CALL symput will be executed 1 million times, each time (1) implicitly converting _N_ to a character expression using BEST12. format and (2) rewriting the NULLDATA value in macro memory from the DATA step, which is quite slow and (3) creating and exact copy of DATA as TEMP, together with its full disk footprint. Quite a work for the computer, eh? Especially considering that all you need is (1) read the descriptor of DATA at compile time without reading any data, (2) find how many observations DATA has, and (3) assign the latter to NULLDATA *just once*. In other words, > > data _null_ ; > call symputx ('nulldata', n) ; > stop ; > set a nobs = n ; > run ; > > or, if you still are using Version 8 (that actually does happen!), use > > call symput ('nulldata', put (n, 32.-L)) ; > > instead. > > Kind regards > ------------ > Paul Dorfman > Jax, FL > ------------ > > > > -------------- Original message ---------------------- > From: NM <neerav.mo...@GMAIL.COM> > > > Hi everyone, > > I have a minor problem that I can't seem to find a solution. I have a > > dataset called TEMP that has 0 observations, after this dataset is > > made, I call a macro that generates some pvalues (2x2 tables based on > > the temp dataset), temp will usually have observations (this is all in > > a loop), however, if the temp dataset has 0 observations, I don't want > > to run my B macro (since it produces errors). Here's a sample of what > > I'm trying to do. > > > %macro a; > > > *this dataset has 0 observations) > > data temp; > > set data; > > call symput ('nulldata',_n_); > > run; > > > %if "&nulldata"=0 %then %do; (I have also tried =' ' but that doesn't > > work either) > > > %macro b; > > > proc freq data=temp; > > tables a*b; > > run; > > > %mend; > > > %b; > > > %end; > > > %mend; > > > So what am I doing wrong here? It should work, but it doesn't. If > > someone can please send a solution (i'm sure it won't be overly > > complex since it's almost done) I would be very grateful. > > > Cheers.- Hide quoted text - > > - Show quoted text -


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