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 (July 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 7 Jul 2008 15:53:15 -0500
Reply-To:     Mary <>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mary <mlhoward@AVALON.NET>
Subject:      Re: SET with OBS=0
Comments: To: "data _null_," <datanull@GMAIL.COM>
Content-Type: text/plain; charset="iso-8859-1"

Yes, but this approach seems to require me to be in the data step to do something, what I really want to do is conditionally execute code after that (usually doing something with the ODS data sets). So checking the count of observations with the SQL statement (and I agree, it is faster to refer to the dictionary), then using the %if macro language allows me to proceed. I really do need to know if I have any observations in my ODS data set, regardless of whether it exists or not, in order to subset it and add it to overall data, as I was doing in the PowerPoint slide thread:

{initialize assign datasets to no data- gets rid of any data that may have existed from previous run } ods output {assign output data sets} proc procname /* if proc runs, datasets with same name get replaced, if not they are still there, that's why the initialization */ check if dataset has any observations with SQL call, put into macro variable

%if &count=0 %then %do; things to do if there's no output in the ODS data set, such as rerun my proc with different parameters. %end;

%if &count > 0 %then %do; output exisits in ODS output data set: subset what I want, then append it to my running total. data ods_set; set ods_set; if (keep_condition); run;

data allset; set allset ods_set; run; %end; The problem with the call execute statement is that it is only one thing, instead of allowing me to just handle the condition and move on- usually I'm trying to aggregate 10,000 runs or so- I **don't** want to stop just because one didn't work. This I believe is similar to the way R does this. This way I handle the messages, and go on, rather than attempting to do something with data sets that don't have any observations in them- sometimes even if a proc runs successfully, it doesn't generate a particular ODS set, so I want to handle that in my code; that way I'm not attempting to merge or aggregate data sets that don't have any data. I have learned the importance of initializing ODS sets; previous ones **do not** go away if SAS does not overwrite them with new ones!!


----- Original Message -----

From: data _null_, To: SAS-L@LISTSERV.UGA.EDU Sent: Monday, July 07, 2008 3:23 PM Subject: Re: SET with OBS=0

On 7/7/08, Mary <> wrote: > > For my case, I want to set the specific data set that I'm specifying in ODS > to have no observations before running the procedure, then I can ask whether > it still has no observations after running the procedure.

But that's not what you're doing. You are counting the observations. Not checking that it is still zero. As you said you can use the dictionary tables to determine if a data set has zero observations or not.

data noObsOrVars; stop; run; proc sql; select memname,nobs from dictionary.tables where libname eq 'WORK' and memname eq 'NOOBSORVARS'; quit; run;

However using this method requires macro variables and macros which may not be needed. You can also code a data step to cause some actions when there are no observations in a data set. Plus you don't need to count anything.

211 data crossTabFreqs; 212 stop; 213 run;

NOTE: The data set WORK.CROSSTABFREQS has 0 observations and 0 variables.

214 ods listing close; 215 ods output crossTabFreqs=crossTabFreqs; 216 proc freq data=sashelp.class; 217 tables sex*age / list; 218 run;

WARNING: Output 'crossTabFreqs' was not created. Make sure that the output object name, label, or path is spelled correctly. Also, verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used. NOTE: There were 19 observations read from the data set SASHELP.CLASS.

219 ods listing; 220 data crossTabFreqs; 221 if _n_ eq 1 and eof then do; 222 put 'NOTE: NO observations'; 223 call execute('*endsas; *perhaps;'); 224 end; 225 set crossTabFreqs end=eof; 226 run;

NOTE: NO observations NOTE: There were 0 observations read from the data set WORK.CROSSTABFREQS. NOTE: The data set WORK.CROSSTABFREQS has 0 observations and 0 variables.

NOTE: CALL EXECUTE generated line. 1 + *endsas; *perhaps;

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