Hi ,
I have the below portion of my code :
IF CURR > DATE_FROM_FORMAT THEN DO ;
INFILE FILENMS DLM ='~' ;
LENGTH FILE2RD $45. ;
INPUT @1 FILE2RD $;
FILE2RD = TRIM(FILE2RD) ;
INFILE DUMMY DLM='~' FILEVAR=FILE2RD DSD MISSOVER ;
IF _N_ = 0 THEN DO ;
PUT 'FILE2RD IS EMPTY' ;
END;
END ;
But the output shown in saslog is :
NOTE: The infile FILENMS is:
Dsname=CHMICST.X.MACRO.SAYAN,
Unit=3390,Volume=BP3043,Disp=SHR,Blksize=27998,
Lrecl=600,Recfm=VB
SAYAN1:CURR=27
SAYAN2:DATE_FROM_FORMAT=15
NOTE: The infile DUMMY is:
Dsname=CHMICST.MPB.INPUT.TSV.SAYAN,
Unit=3390,Volume=BL3186,Disp=SHR,Blksize=4500,
Lrecl=1500,Recfm=VB
NOTE: 1 record was read from the infile FILENMS.
The minimum record length was 71.
The maximum record length was 71.
NOTE: 0 records were read from the infile DUMMY.
I want to generate a report if the input file 'DUMMY' is having no records. How can I do that ?
You need to use INFILE statement option END= and check it before you try to read any records. For example.
28 filename FT15F001 temp;
29 parmcards;
30 ;;;;
31 run;
32 data _null_;
33 filevar = pathname('FT15F001','F');
34 infile dummy filevar=filevar END=EOF;
35 if eof then do;
36 putlog 'NOTE: EOF on ' Filevar= ;
37 end;
38 do while(not eof);
39 input;
40 putlog _infile_;
41 end;
42 stop;
43 run;
NOTE: The infile DUMMY is:
(system-specific pathname),
(system-specific file attributes)
NOTE: EOF on filevar=system-specific pathname
NOTE: 0 records were read from the infile (system-specific pathname).
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
data _null_; set sashelp.table (where=(libname="<your lib>" and memname="<your data>" and nobs=0)); call execute('proc report <do rest of report>; run;'); run;
With the above, from the metadata only 1 row will be returned if the dataset has zero obs, that way the call execute will only be executed if the obs=0, otherwise it will not do anything. Note <your lib> is the library name in caps, <your data> is your dataset name in caps. And <do rest of report> needs to be replaced with the proc report information.
Thanks, but that is not what I asked for
See the example above that shows how to print a message if the dataset is empty
Reeza I specifically mentioned infile not a sas dataset,.. i am reading the infile dummy from filevar.
Please help me to write a report if the dummy file is empty.
*****not a sas dataset*****
Try next code:
IF CURR > DATE_FROM_FORMAT THEN DO ;
INFILE FILENMS DLM ='~' ;
LENGTH FILE2RD $45. ;
INPUT @1 FILE2RD $;
FILE2RD = TRIM(FILE2RD) ;
INFILE DUMMY DLM='~' FILEVAR=FILE2RD DSD MISSOVER eov=done ;
retain m 0;
input;
IF done and m= 0 THEN DO ;
PUT 'FILE2RD IS EMPTY' ;
END;
m+1;
END ;
Hi Shmuel,
Thanks for the next portion
but this didnt work :
IF CURR > DATE_FROM_FORMAT THEN DO ;
INFILE FILENMS DLM ='~' ;
LENGTH FILE2RD $45. ;
INPUT @1 FILE2RD $;
FILE2RD = TRIM(FILE2RD) ;
INFILE DUMMY DLM='~' FILEVAR=FILE2RD DSD MISSOVER EOV=DONE ;
RETAIN M 0;
INPUT ;
IF DONE AND M=0 THEN DO ;
PUT 'FILE2RD IS EMPTY' ;
END;
M+1 ;
END ;
Post the full code and log.
//CHXXROCK JOB EI4605,
// 'S.DIONNE.BLDG-610',
// CLASS=S,
// MSGCLASS=X,
// MSGLEVEL=(1,1),
// NOTIFY=&SYSUID,
// RD=NC,
// RESTART=*
//*
//TEST1 EXEC SAS
//FILENMS DD DISP=SHR,DSN=CHMICST.X.MACRO.SAYAN
//SASLIB DD DSN=CHMICST.SAS.CODE.NEWDEV,DISP=SHR
//EMAIL DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
OPTIONS SOURCE SOURCE2 NOCENTER;
DATA _NULL_ ;
%INCLUDE SASLIB(TEST) ;
RUN ;
DATA MACRO_FILES ;
LENGTH BLUE_FILE_NAME
RESPONSIBLE_PERSON $200.
;
INFILE FILENMS DELIMITER='~' DSD MISSOVER END=LASTOBS;
INPUT @1 BLUE_FILE_NAME
RESPONSIBLE_PERSON
;
BLUE_FILE_NAME = UPCASE(BLUE_FILE_NAME);
RESPONSIBLE_PERSON = UPCASE(RESPONSIBLE_PERSON);
IF BLUE_FILE_NAME = 'BLUE_FILE_NAME' THEN DELETE ;
IF RESPONSIBLE_PERSON = 'RESPONSIBLE_PERSON' THEN DELETE ;
DATA EMPTY_FILES ;
SET MACRO_FILES;
KEEP BLUE_FILE_NAME RESPONSIBLE_PERSON ;
DATE_FROM_FORMAT = INPUT(BLUE_FILE_NAME,TEST.) ;
TODAY=COMPRESS(PUT(TODAY(),MMDDYYN7.));
CURR=SUBSTR(TODAY,3,2);
PUT @4 'SAYAN1:' CURR= ;
PUT @4 'SAYAN2:' DATE_FROM_FORMAT=;
IF CURR > DATE_FROM_FORMAT THEN DO ;
INFILE FILENMS DLM ='~' ;
LENGTH FILE2RD $45. ;
INPUT @1 FILE2RD $;
FILE2RD = TRIM(FILE2RD) ;
INFILE DUMMY DLM='~' FILEVAR=FILE2RD DSD MISSOVER EOV=DONE ;
RETAIN M 0;
INPUT ;
IF DONE AND M=0 THEN DO ;
PUT 'FILE2RD IS EMPTY' ;
END;
M+1 ;
END ;
file : CHMICST.X.MACRO.SAYAN : CHMICST.MPB.INPUT.TSV.SAYAN~Sayan.Chakraborty1@ge.com
saslib : 'CHMICST.SAS.CODE.NEWDEV(test)' :
PROC FORMAT;
INVALUE TEST
'CHMICST.MPB.INPUT.TSV.SAYAN' = 15
;
SASLOG :
NOTE: The infile FILENMS is:
Dsname=CHMICST.X.MACRO.SAYAN,
Unit=3390,Volume=BP3043,Disp=SHR,Blksize=27998,
Lrecl=600,Recfm=VB
NOTE: 1 record was read from the infile FILENMS.
The minimum record length was 71.
The maximum record length was 71.
NOTE: The data set WORK.MACRO_FILES has 1 observations and 2 variables.
NOTE: The DATA statement used 0.01 CPU seconds and 14461K.
NOTE: The address space has used a maximum of 632K below the line and 15592K above the line.
NOTE: Character values have been converted to numeric values at the places give
32:6
NOTE: The infile FILENMS is:
Dsname=CHMICST.X.MACRO.SAYAN,
Unit=3390,Volume=BP3043,Disp=SHR,Blksize=27998,
Lrecl=600,Recfm=VB
SAYAN1:CURR=27
SAYAN2:DATE_FROM_FORMAT=15
NOTE: The infile DUMMY is:
Dsname=CHMICST.MPB.INPUT.TSV.SAYAN,
Unit=3390,Volume=BL3186,Disp=SHR,Blksize=4500,
Lrecl=1500,Recfm=VB
NOTE: 1 record was read from the infile FILENMS.
The minimum record length was 71.
The maximum record length was 71.
NOTE: 0 records were read from the infile DUMMY.
NOTE: There were 1 observations read from the data set WORK.MACRO_FILES.
NOTE: The data set WORK.EMPTY_FILES has 0 observations and 2 variables.
NOTE: The DATA statement used 0.02 CPU seconds and 14642K.
You need to use INFILE statement option END= and check it before you try to read any records. For example.
28 filename FT15F001 temp;
29 parmcards;
30 ;;;;
31 run;
32 data _null_;
33 filevar = pathname('FT15F001','F');
34 infile dummy filevar=filevar END=EOF;
35 if eof then do;
36 putlog 'NOTE: EOF on ' Filevar= ;
37 end;
38 do while(not eof);
39 input;
40 putlog _infile_;
41 end;
42 stop;
43 run;
NOTE: The infile DUMMY is:
(system-specific pathname),
(system-specific file attributes)
NOTE: EOF on filevar=system-specific pathname
NOTE: 0 records were read from the infile (system-specific pathname).
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
Thanks a lot
You can use the methods suggested to check the file, but it's not a direct check of the file.
What are you checking the file for? Empty or non existence? Or will it have just a row header? I wonder if it's worth using FINFO type functions instead.
@sayanapex06 wrote:
Reeza I specifically mentioned infile not a sas dataset,.. i am reading the infile dummy from filevar.
Please help me to write a report if the dummy file is empty.
*****not a sas dataset*****
Please show exactly what the report for the empty table should look like.
You are expecting us to read your mind as to what the content of said report may be. You have been given a couple of examples but have not provided any detail as to why they are not acceptable.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.