View previous topic :: View next topic
|
Author |
Message |
ap_mainframes
Active User
Joined: 29 Dec 2005 Posts: 181 Location: Canada
|
|
|
|
Hi,
Here is the requirement which needs to be met in SAS.
I have a SAS program which is writing a report.The report has a header.
This report is generated by a input file.
The requirement is, if the input file is empty, then I still need to just write the header record.
How can I do this ?? Any help is appreciated.
Thanks |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
SAS processing of empty files is well documented on their support page. Code I've used successfully in the past is:
Code: |
DATA DUMMY;
INPUT VAR1;
CARDS;
DATA TWO;
%LET DNAME=DUMMY; /* NAME OF SAS DATA SET TO CHECK */
%MACRO NUMOBS(DSN);
%GLOBAL NUM;
DATA _NULL_;
IF 0 THEN SET &DSN NOBS=COUNT;
CALL SYMPUT('NUM',LEFT(PUT(COUNT,8.)));
STOP;
RUN;
%MEND NUMOBS;
%MACRO CHECK;
%LOCAL ONE;
%NUMOBS(&DNAME);
%LET ONE=#
%IF &ONE NE 0 %THEN %DO;
TITLE "THE &DNAME DATA SET";
PROC PRINT DATA=&DNAME;
%END;
%ELSE %DO;
%PUT WARNING: THE DATA SET IS EMPTY ;
%END;
%MEND;
%CHECK
RUN; |
|
|
Back to top |
|
|
ap_mainframes
Active User
Joined: 29 Dec 2005 Posts: 181 Location: Canada
|
|
|
|
Thanks for your reply.
Can some please help me find the issue with my code shown below:
Code: |
PROC SORT DATA=FILEABC;
BY POLICY;
DATA FILEABC;
RETAIN CNT 0;
SET FILEABC;
FILE OUTRPT NOTITLES NOPRINT;
BY POLICY;
IF FILEABC_EOF AND CNT = 0 THEN DO;
PUT ' DATASET IS EMPTY ';
END; |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The issue with your code is that it won't work. You need to use something like what I've posted because of the way SAS handles empty files; it won't let you do the processing of the DATA step as you posted unless there's at least one record in the file. If you don't use a macro, empty file processing won't work in SAS -- check the support & training section of Use [URL] BBCode for External Links to find multiple ways of handling empty files -- none of which use your technique. |
|
Back to top |
|
|
|