Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Empty file in SAS

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
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    Post subject: Empty file in SAS
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: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Tue Dec 09, 2008 9:48 pm    Post subject:
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    Post subject: Reply to: Empty file in SAS
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: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Tue Dec 09, 2008 11:48 pm    Post subject:
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 www.sas.com 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    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am
No new posts File processing vishwakotin Mainframe Interview Questions 9 Fri Apr 28, 2017 11:38 am
No new posts Occurrence of various strings within ... TS70363 JCL & VSAM 1 Thu Apr 27, 2017 8:18 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us