IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Empty file in SAS


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Tue Dec 09, 2008 9:43 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 09, 2008 9:48 pm
Reply with quote

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
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Tue Dec 09, 2008 10:47 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 09, 2008 11:48 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top