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
 

 

Record Count Message in SAS

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Thu Dec 01, 2011 8:57 pm    Post subject: Record Count Message in SAS
Reply with quote

I am using 'FILENAME outmail EMAIL' to send notification. But I couldn't use that conditionally. That is notify only when input dataset is empty.


Code:

//INPUT    DD  DSN=TEST.FILE1,DISP=SHR                     
//SYSIN    DD *                                           
DATA _NULL_;                                               
INFILE INPUT;                                             
INPUT;                                                     
IF _N_ = 10 THEN DO;                                       
   PUT '!!! RECORDS FOUND IN DISCARD FILE !!!';           
    FILENAME MYEMAIL EMAIL FROM=("MYEMAIL@YAHOO.COM")     
    TO=("MYEMAIL@YAHOO.COM")                               
    SUBJECT = "AN ALERT TO NOTIFY NON-EMPTY";             
    FILE MYEMAIL;                                         
    PUT "THE INPUT FILE HAS DISCARD RECORDS."             
   ABORT RETURN 16;                                       
END;                                                       
RUN;                                                       
//SASLOG   DD  SYSOUT=*                                   


This sends note even the input is empty or not 10 records as the email created complie time itself.

Kindly help me out if any other technique could be used to overcome this.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Dec 01, 2011 10:35 pm    Post subject:
Reply with quote

Here's a set of macros I use to send different messages based on whether or not the input SAS data set is empty:
Code:
%MACRO GOTDATA ;
PROC PRINT DATA=MERGED  SPLIT='*';
     ID USERNAME1 ;
     VAR RACFID RACFLON TERM_DATE PERSONNEL_NO ;
     FORMAT TERM_DATE RACFLON YYMMDDS10. ;
     TITLE1 'FIRST, MIDDLE, LAST NAME MATCHES WITH RACF';
     TITLE2 "TERMINATIONS LIST FOR %PERSTART TO %PEREND" ;
     LABEL RACFID       = 'USER ID'
           USERNAME1    = 'USER NAME'
           RACFLON      = 'LAST LOGON'
           TERM_DATE    = 'TERM DATE'
           PERSONNEL_NO = 'HR*PERSONNEL*NUMBER'
           ;
%MEND  GOTDATA ;

%MACRO SENDMSG ;
PROC PRINT DATA=MERGED  SPLIT='*';
     ID USERNAME1 ;
     VAR RACFID RACFLON TERM_DATE PERSONNEL_NO ;
     FORMAT TERM_DATE RACFLON YYMMDDS10. ;
     TITLE1 'FIRST, LAST NAME MATCHES WITH RACF';
     TITLE2 "TERMINATIONS LIST FOR %PERSTART TO %PEREND" ;
     LABEL RACFID       = 'USER ID'
           USERNAME1    = 'USER NAME'
           RACFLON      = 'LAST LOGON'
           TERM_DATE    = 'TERM DATE'
           PERSONNEL_NO = 'HR*PERSONNEL*NUMBER'
           ;
RUN;
%MEND  SENDMSG ;

%MACRO CHECKDS(DSN);
   %IF %SYSFUNC(EXIST(&DSN)) %THEN
       %DO;
          %LET DSID=%SYSFUNC(OPEN(&DSN));
          %LET NUM=%SYSFUNC(ATTRN(&DSID,NOBS));
          %LET RC=%SYSFUNC(CLOSE(&DSID));
          %IF &NUM > 0 %THEN
          %DO;
*            %GOTDATA ;
             ODS HTML FILE=TEMP RS=NONE;
             %SENDMSG ;
             ODS HTML CLOSE;
             RUN;
          %END;
          %ELSE %DO ;
             DATA _NULL_ ;
             FILE TEMP    ;
             PUT "There were no terminations for mainframe users "
             "for %PERSTART to %PEREND"
             ;
                %END ;
       %END;
       %ELSE %DO ;
          DATA _NULL_ ;
          FILE TEMP    ;
          PUT "There were no terminations for mainframe users "
          "for %PERSTART to %PEREND"
          ;
             %END ;
%MEND CHECKDS;
FILENAME TEMP EMAIL
              TO=("RSAMPLE@XXX.COM"
                 )
              SUBJECT="Terminations list for %PERSTART to %PEREND"
              TYPE='TEXT/HTML';
%CHECKDS(MERGED)
MERGED is the SAS work data set that I'm using.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Fri Dec 02, 2011 12:37 pm    Post subject:
Reply with quote

Hi,
Quote:
That is notify only when input dataset is empty.

You say that you want to send email when dataset is empty, but the code appears to send email if the dataset has 10 or more observations(non-empty)? Is this the correct scenario?
Code:
IF _N_ = 10 THEN DO;
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Fri Dec 02, 2011 3:13 pm    Post subject:
Reply with quote

SAS increments _N_ by 1 at the beginning of each DATA step iteration.

So _N_ has nothing to do with an infile record count. It is the number of
datastep iterations.

You are not using the END variable or EOF label to check for
end of data. Try to use OBS to determine if there are 10 or more records,
or define/use a record counter.
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Fri Dec 02, 2011 4:12 pm    Post subject:
Reply with quote

Thanks for the suggestions.

Will try out and let you know.
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Sat Dec 03, 2011 1:55 am    Post subject:
Reply with quote

Hi Robert,

How to map dataset to the DSN MERGED?

I am using like this and the control was going to NOT EXIST Condition

Code:

//INPUT    DD  DSN=CASBALA.SAS.NOEMPTY.TESTFILE,DISP=SHR   
//SYSIN    DD *                                             
%MACRO SENDMSG;                                             
TITLE1 'TEST MESSAGE' ;                                     
RUN;                                                       
%MEND SENDMSG;                                             
                                                           
%MACRO CHECKDS(DSN);                                       
  %IF %SYSFUNC(EXIST(&DSN)) %THEN                           
  %DO;                                                     
    %LET DSID=%SYSFUNC(OPEN(&DSN));                         
    %LET NUM=%SYSFUNC(ATTRN(&DSID,NOBS));                   
    %LET RC=%SYSFUNC(CLOSE(&DSID));                         
    %IF &NUM > 0 %THEN                                     
    %DO;                                                   
      ODS HTML FILE=TEMP RS=NONE;                           
      %SENDMSG;                                             
      OSD HTML CLOSE;                                       
      RUN;                                                 
    %END;                                                   
    %ELSE %DO;                                                 
    DATA _NULL_ ;                                             
    FILE TEMP;                                                 
    PUT "THERE WERE NO INCORRECT VALUE";                       
    %END;                                                     
  %END;                                                       
  %ELSE %DO;                                                   
  DATA _NULL_;                                                 
  FILE TEMP;                                                   
  PUT "NOT PROPER FILE";                                       
  %END;                                                       
 %MEND CHECKDS;                                               
 FILENAME TEMP EMAIL TO=("test@xyz.com") 
                     SUBJECT="TEST"                           
                     TYPE='TEXT/HTML';                         
 %CHECKDS(INPUT)                                               


Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Sat Dec 03, 2011 2:12 am    Post subject:
Reply with quote

The data set to be checked is assumed to be a SAS data set -- not a DD statement. Change your code to
Code:
//SYSIN DD *
DATA INPUT ;
     INFILE INPUT ;
     INPUT @;
%MACRO SENDMSG ;
and I believe it'll work -- although I haven't tested it.
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Sat Dec 03, 2011 2:21 am    Post subject:
Reply with quote

still it is going into NOT EXIST condition. Let me try someother way.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Sat Dec 03, 2011 1:48 pm    Post subject:
Reply with quote

Try this :

Code:

//INPUT    DD  DSN=TEST.FILE1,DISP=SHR                     
//SYSIN    DD *                                           
DATA _NULL_;                                               
RETAIN RECCNT 0;
INFILE INPUT EOF=FINISHED;                                             
INPUT;
RECCNT = RECCNT + 1;
IF RECCNT = 10 THEN DO;                                       
   PUT '!!! RECORDS FOUND IN DISCARD FILE !!!';           
    FILENAME MYEMAIL EMAIL FROM=("MYEMAIL@YAHOO.COM")     
    TO=("MYEMAIL@YAHOO.COM")                               
    SUBJECT = "AN ALERT TO NOTIFY NON-EMPTY";             
    FILE MYEMAIL;                                         
    PUT "THE INPUT FILE HAS DISCARD RECORDS."             
   ABORT RETURN 16;                                       
END;
RETURN;
FINISHED:
  STOP;                                                       
RUN;         
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Sat Dec 03, 2011 7:17 pm    Post subject:
Reply with quote

Peter,
The problem with this method is it sends email in both cases (empty and non-empty).
FILENAME EMAIL will open the email on complie time itself and the email will be sent anyway.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Sat Dec 03, 2011 7:26 pm    Post subject:
Reply with quote

Have you considered doing a check on the input file using your sort product, or IDCAMS before executing the SAS step conditionally.
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Sat Dec 03, 2011 7:36 pm    Post subject:
Reply with quote

I have tasked to do this with SAS!!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Sat Dec 03, 2011 8:27 pm    Post subject: Reply to: Record Count Message in SAS
Reply with quote

You've been tasked not to send an e-mail. It doesn't matter what product you don't send it from, does it? Then send when necessary from SAS.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Sun Dec 04, 2011 12:26 am    Post subject:
Reply with quote

ABaluchamy wrote:
Peter,
The problem with this method is it sends email in both cases (empty and non-empty).
FILENAME EMAIL will open the email on complie time itself and the email will be sent anyway.


I think that you are telling me a lot of crap. Show me the SAS output of my example, and by that i mean the sysout/sysprint/jeslog.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Sun Dec 04, 2011 4:14 pm    Post subject: Re: Record Count Message in SAS
Reply with quote

ABaluchamy wrote:
I am using 'FILENAME outmail EMAIL' to send notification. But I couldn't use that conditionally. That is notify only when input dataset is empty.

Kindly help me out if any other technique could be used to overcome this.


This topic is getting murky at the moment.

Perhaps the OP can resolve this by explaining exactly what is required here, and all this nonesense about empty and ten records.

My understanding is that there is an input file and if that file is empty then send an email, else do not send the email.

I have given you a simple resolution to this, and then you come back later and say it has to be done by SAS, but you did not state this at the start of the topic, so thank you for allowing me to waste my time.

The others have given some great advice and code which IMO is food for thought, or even a direct solution, but then you come back with that classic saying it didn't work with no further explanation.

Now, why don't you write it down in such a simple way that there can be no misunderstandings and perhaps you will get some help.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Sun Dec 04, 2011 4:33 pm    Post subject:
Reply with quote

To be fair - on one point only - the topic is RECORD COUNT MESSAGE IN SAS
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Mon Dec 05, 2011 8:43 am    Post subject:
Reply with quote

Mr expat,

I didn't intend to waste anyone's time.

Robersample's example code are relavent to me. I'm taking them to workout things.

Thanks anyways.
Back to top
View user's profile Send private message
Vidhya Kalyanasundaram

New User


Joined: 19 Jul 2007
Posts: 30
Location: chennai

PostPosted: Wed Dec 07, 2011 1:31 pm    Post subject: Re: Conditionally sending email through SAS program
Reply with quote

Hi,

Please find below the sample code, which would help you to send email conditionally. You could modify according to your requirement.

Code:
//*-------------------------------------------------------------------
//* STEP   : R010                                                     
//* DESCR  : 1.THIS STEP ENDS WITH RC 4 IF DISCARD FILE IS EMPTY       
//*          2.THIS STEP ENDS WITH RC 0 IF DISCARD FILE'S RECORD COUNT
//*            IS LESS THAN AND NOT EQUALS 10                         
//*            - AN ALERT EMAIL ALSO WILL BE SENT TO PROD SUPPORT TEAM   
//*              FOR NOTIFICATION                         
//*          3.THIS STEP ENDS WITH RC 16 IF DISCARD FILE'S RECORD COUNT
//*            IS GREATER THAN OR EQUALS 10                           
//* PROGRAM: SAS                                                       
//* NOTES  : TESTED WITH SAMPLE EMAIL ID
//*          MODIFY ACCORDING TO YOUR NEED____________________________
//*-------------------------------------------------------------------
//R010     EXEC SAS                                                   
//*DDNAME   DD  DSN=INFILE.EMPTY.ZERORECS,DISP=SHR            Empty input file       
//DDNAME    DD  DSN=INFILE.NOEMPTY.LTENRECS,DISP=SHR            Non-Empty input file with 9 recs     
//*DDNAME   DD  DSN=INFILE.NOEMPTY.TENRECS,DISP=SHR            Non-Empty input file with 10 recs     
//SYSIN    DD *                                                       
 DATA INPUTDATA;                                                       
 INFILE DDNAME;
 /* CODE LRECL AS THE LENGTH OF THE DATATYPE */                                                       
 INPUT @01 RECORD    $CHAR362.;                                                          
 *;                                                                   
 /* PROC SQL TO GET THE INPUT FILE RECORD COUNT */                   
 PROC SQL;                                                           
  CREATE VIEW QUERY AS                                               
   SELECT COUNT(RECORD) AS COUNT FROM INPUTDATA;                     
 *;                                                                   
 DATA V_VIEW;                                                         
  SET QUERY;                                                         
 /* DISPLAY STATEMENT TO PRINT THE RECORD COUNT IN SYSOUT */         
  PUT 'RECORD COUNT RETURNED FROM SQL QUERY:' COUNT;                                             
 *;                                                                   
 /* DEFINE EMAIL CONFIGURATION */                                     
   FILENAME NOTIFY EMAIL;                                             
 *;                                                                   
 /* FORCE RC 16 IF COUNT IS GREATER THAN 10 */                       
 IF COUNT GE 10 THEN ABORT RETURN 16;                                 
 *;                                                                   
 /* SEND AN ALERT EMAIL IF COUNT IS LESSER THAN AND NOT EQUALS 10 */     
 IF COUNT LT 10 AND COUNT NE 0 THEN DO;                               
   /* CUSTOMIZING EMAIL CONFIGURATION AT DATA SETP */                   
   FILE NOTIFY;
   /* EMAIL FROM ADDRESS */                                                         
   PUT '!EM_FROM!' "TO_EMAIL_ADDRESS@GMAIL.COM";
   /* EMAIL TO ADDRESS */                   
   PUT '!EM_TO!' "FROM_EMAIL_ADDRESS@GMAIL.COM";
   /* EMAIL SUBJECT */                     
   PUT '!EM_SUBJECT!' "WARNING : LESS THAN 10 RECORDS IN DISCARD FILE"
   /* EMAIL CONTENT */     
   PUT / "THIS IS AN ALERT EMAIL TO NOTIFY PROD SUPPORT TEAM";   
   PUT / "LESS THAN 10 RECORDS ARE FOUND IN DISCARD FILE";             
   END;                                                               
RUN;                                                                   
 *;                                                                   
//SASLOG   DD  SYSOUT=*                                               
//SYSOUT   DD  SYSOUT=*                                               
//SYSPRINT DD  SYSOUT=*                                               
//SYSUDUMP DD  SYSOUT=A


-- 
Thanks,
Vidhya
"If you have knowledge, let others light their candles with it. "
Back to top
View user's profile Send private message
Vidhya Kalyanasundaram

New User


Joined: 19 Jul 2007
Posts: 30
Location: chennai

PostPosted: Wed Dec 07, 2011 1:34 pm    Post subject: Re: Solution posted
Reply with quote

Code:
//*-------------------------------------------------------------------
//* STEP   : R010                                                     
//* DESCR  : 1.THIS STEP ENDS WITH RC 4 IF DISCARD FILE IS EMPTY       
//*          2.THIS STEP ENDS WITH RC 0 IF DISCARD FILE'S RECORD COUNT
//*            IS LESS THAN AND NOT EQUALS 10                         
//*            - AN ALERT EMAIL ALSO WILL BE SENT TO PROD SUPPORT TEAM   
//*              FOR NOTIFICATION                         
//*          3.THIS STEP ENDS WITH RC 16 IF DISCARD FILE'S RECORD COUNT
//*            IS GREATER THAN OR EQUALS 10                           
//* PROGRAM: SAS                                                       
//* NOTES  : TESTED WITH SAMPLE EMAIL ID   
//*          MODIFY ACCORDING TO YOUR NEED____________________________
//*-------------------------------------------------------------------
//R010     EXEC SAS                                                   
//*DDNAME   DD  DSN=INFILE.EMPTY.ZERORECS,DISP=SHR            Empty input file       
//DDNAME    DD  DSN=INFILE.NOEMPTY.LTENRECS,DISP=SHR            Non-Empty input file with 9 recs     
//*DDNAME   DD  DSN=INFILE.NOEMPTY.TENRECS,DISP=SHR            Non-Empty input file with 10 recs     
//SYSIN    DD *                                                       
 DATA INPUTDATA;                                                       
 INFILE DDNAME;
 /* CODE LRECL AS THE LENGTH OF THE DATATYPE */                                                       
 INPUT @01 RECORD    $CHAR362.;                                                          
 *;                                                                   
 /* PROC SQL TO GET THE INPUT FILE RECORD COUNT */                   
 PROC SQL;                                                           
  CREATE VIEW QUERY AS                                               
   SELECT COUNT(RECORD) AS COUNT FROM INPUTDATA;                     
 *;                                                                   
 DATA V_VIEW;                                                         
  SET QUERY;                                                         
 /* DISPLAY STATEMENT TO PRINT THE RECORD COUNT IN SYSOUT */         
  PUT 'RECORD COUNT RETURNED FROM SQL QUERY:' COUNT;                                             
 *;                                                                   
 /* DEFINE EMAIL CONFIGURATION */                                     
   FILENAME NOTIFY EMAIL;                                             
 *;                                                                   
 /* FORCE RC 16 IF COUNT IS GREATER THAN 10 */                       
 IF COUNT GE 10 THEN ABORT RETURN 16;                                 
 *;                                                                   
 /* SEND AN ALERT EMAIL IF COUNT IS LESSER THAN AND NOT EQUALS 10 */     
 IF COUNT LT 10 AND COUNT NE 0 THEN DO;                               
   /* CUSTOMIZING EMAIL CONFIGURATION AT DATA SETP */                   
   FILE NOTIFY;
   /* EMAIL FROM ADDRESS */                                                         
   PUT '!EM_FROM!' "TO_EMAIL_ADDRESS@GMAIL.COM";
   /* EMAIL TO ADDRESS */                   
   PUT '!EM_TO!' "FROM_EMAIL_ADDRESS@GMAIL.COM";
   /* EMAIL SUBJECT */                     
   PUT '!EM_SUBJECT!' "WARNING : LESS THAN 10 RECORDS IN DISCARD FILE"
   /* EMAIL CONTENT */     
   PUT / "THIS IS AN ALERT EMAIL TO NOTIFY PROD SUPPORT TEAM";   
   PUT / "LESS THAN 10 RECORDS ARE FOUND IN DISCARD FILE";             
   END;                                                               
RUN;                                                                   
 *;                                                                   
//SASLOG   DD  SYSOUT=*                                               
//SYSOUT   DD  SYSOUT=*                                               
//SYSPRINT DD  SYSOUT=*                                               
//SYSUDUMP DD  SYSOUT=A     


-- 
Thanks,
Vidhya
"If you have knowledge, let others light their candles with it. "
Back to top
View user's profile Send private message
ABaluchamy

New User


Joined: 29 Dec 2006
Posts: 34
Location: INDIA

PostPosted: Wed Dec 07, 2011 2:55 pm    Post subject:
Reply with quote

That worked..!! Many Thanks.
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 How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts How to show message using batch jobs madprasy TSO/ISPF 7 Fri Sep 09, 2016 6:55 pm


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