View previous topic :: View next topic
|
Author |
Message |
aprak00 Warnings : 2 New User
Joined: 09 Aug 2006 Posts: 24
|
|
|
|
Could anyone please help me to identify a blank SAS dataset?
The scenario is I need to do some processing if a SAS dataset is blank else use the records in the SAS dataset. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Fields or variables can be blank. Do you mean empty, or non-existent?
If empty, input it via SET, with OPTIONS OBS=1, and see if you have a record. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Or do you mean a dataset that has been created, allegedly, by SAS but has no internal files. i.e. the physical dataset exists and the previous SAS job(s) have not written to it in any way.
PROC DATASETS should do the trick if this is the case. |
|
Back to top |
|
|
rajesh_1183
Active User
Joined: 24 Nov 2005 Posts: 121 Location: Tadepalligudem
|
|
|
|
Code: |
DATA DS1;
INFILE DDNAME1(END=DONE);
INPUT @001 REC1 $80.;
RUN;
DATA DS2;
SET DS1;
IF DONE AND _N_ >=1 THEN PUT ' DATASET NOT EMPTY ';
IF DONE AND _N_ <=1 THEN PUT ' DATASET EMPTY ';
RUN;
|
This might work...
Thanks,
Rajesh |
|
Back to top |
|
|
Alan Voss
New User
Joined: 29 Nov 2006 Posts: 32 Location: Jacksonville, FL
|
|
|
|
Code: |
DATA WORK.ABC;
INFILE INSTUFF;
INPUT ...;
run;
proc sql noprint;
select nobs into :abcnobs separated by ' '
from dictionary.tables
where libname = 'WORK'
and memname = 'ABC';
quit;
%put &abcnobs; /* show number of obs */
|
|
|
Back to top |
|
|
aprak00 Warnings : 2 New User
Joined: 09 Aug 2006 Posts: 24
|
|
|
|
Hi Alan,
Thanks for the info..
But the "abcnobs" in the code above is returning a junk value not the no: of obs in WORK.ABC.
Could you please let me know the reason?
I used the following code:
Code: |
PROC SQL NOPRINT;
SELECT NOBS INTO :N_OBS
FROM DICTIONARY.TABLES
WHERE LIBNAME = "WORK"
AND MEMNAME = "TESTO";
QUIT;
%PUT &N_OBS; |
|
|
Back to top |
|
|
Alan Voss
New User
Joined: 29 Nov 2006 Posts: 32 Location: Jacksonville, FL
|
|
|
|
I don't understand why you got a "junk value".
Following is my SAS log of WORK.TESTO which I have copied from SASHELP.CLASS (19 observations). Please note, if you don't use the separated by ' ', PROC SQL will not trim off leading blanks.
NOTE: AUTOEXEC processing completed.
1 data work.TESTO;
2 set sashelp.class;
3 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TESTO has 19 observations and 5 variables.
NOTE: DATA statement used:
real time 0.02 seconds
cpu time 0.02 seconds
4
5 PROC SQL NOPRINT;
6 SELECT NOBS INTO :N_OBS
7 FROM DICTIONARY.TABLES
8 WHERE LIBNAME = "WORK"
9 AND MEMNAME = "TESTO";
10 QUIT;
NOTE: PROCEDURE SQL used:
real time 0.01 seconds
cpu time 0.01 seconds
11 %PUT !&N_OBS!;
! 19!
12 PROC SQL NOPRINT;
13 SELECT NOBS INTO :N_OBS separated by ' '
14 FROM DICTIONARY.TABLES
15 WHERE LIBNAME = "WORK"
16 AND MEMNAME = "TESTO";
17 QUIT;
NOTE: PROCEDURE SQL used:
real time 0.00 seconds
cpu time 0.00 seconds
18 %PUT !&N_OBS!;
!19!
|
|
Back to top |
|
|
|