Date: Mon, 7 Jul 2008 14:30:36 -0500
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: SET with OBS=0
Content-Type: text/plain; charset="iso-8859-1"
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. ODS data sets apparently don't get created if the procedure doesn't run, so that's why I'm making sure that they are there regardless, then use a Proc SQL statement to ask about the number of observations.
However, I just learned today from Patrice's code that I can query the data dictionary tables and that will work.
The first SQL code doesn't work with the data set created this way (because there aren't any variables in the data set), but the second one does work:
data nodata;
stop;
run;
proc sql noprint;
select count(*) as count into :count
from nodata;
quit;
%put &count;
proc sql;
select
nobs into :count
from dictionary.Tables
where libname = upcase("WORK") and
memname = upcase("NoData");
quit;
%put &count;
But had I created the data set with at least one variable and no observations, it would have worked:
data nodata;
informat dummy 1.;
stop;
run;
proc sql noprint;
select count(*) as count into :count
from nodata;
quit;
%put &count;
-Mary
----- Original Message -----
From: data _null_,
To: Mary
Cc: SAS-L@listserv.uga.edu
Sent: Monday, July 07, 2008 1:15 PM
Subject: Re: SET with OBS=0
You might prefer no obs or variables.
data noObsOrVariables;
stop;
run;
On 7/7/08, Mary <mlhoward@avalon.net> wrote:
> And if you want to create a SAS data set with no observations, here is one way. I've discovered that I can't just drop the variable or the SQL statement asking about count(*) won't work. I use these to "initialize" ODS data sets, and then check after the procedure has been run whether they've had observations added to them.
>
> data association_set;
>
> informat dummy 1.;
>
> if dummy=. then delete;
>
> run;
>
>
>
> -Mary
>
> ----- Original Message -----
> From: Talbot Michael Katz
> To: SAS-L@LISTSERV.UGA.EDU
> Sent: Monday, July 07, 2008 12:50 PM
> Subject: SET with OBS=0
>
>
> Hi.
>
> I was experimenting with the following code in SAS 9.01.01M3P020206 on
> HPUX:
>
> %let obsn=0;
> data _null_;
> set myds (obs=&obsn.) nobs=nobs;
> put nobs=;
> call symput ("nobs",nobs);
> run;
> %put nobs = &nobs.;
>
> The put statement produced no output and the %put issued a warning that
> nobs did not resolve. If I change macro variable obsn to 1 then
> everything works okay. I wanted to use SET with OBS=0 as a way of getting
> some information, like the number of observations, without actually
> reading any observation information into the data vector. Obviously,
> there are alternatives, such as OPEN and ATTRN, but my questions are:
> Is there a way to get the number of observations from SET and OBS=0 (in
> other words, did I do something wrong)?
> What information can you get from SET and OBS=0, if anything?
>
> Thanks!
>
> -- TMK --
> "The Macro Klutz"
>