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
 

 

SAS Comparing a Packed decimal date and normal date

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

New User


Joined: 09 Aug 2008
Posts: 7
Location: Hyderabad

PostPosted: Thu Mar 12, 2009 8:39 pm    Post subject: SAS Comparing a Packed decimal date and normal date
Reply with quote

Hi i am trying to read the date from a parmcard and compare it with date on the input file.

reading date from Parm card and converting it in 6 digit date.Parm card date is yyyymmdd:

Code:
INPUT @3 CYCLEYY  $CHAR2.         
   
       @5 CYCLEMM  $CHAR2.             
       @7 CYCLEDD  $CHAR2.;           
CYCLEDT2=MDY(CYCLEMM,CYCLEDD,CYCLEYY);
FORMAT CYCLEDT2 YYMMDD6.;           


reading the inout file
Code:
INPUT

@125 ODS_I4_DDT                PD4.0   --> inPut file field (yymmdd)

ACCTDATE = INPUT(PUT(ODS_I4_DDT,Z6.),YYMMDD6.);
ACCTDATE = COMPRESS((ACCTDATE,YYMMDD8.),'-'); 

IF (CyCledt =  ACCTDATE)  THEN go to NONEFTs;
else   go to EFTS;


irrespecive of the date in the input file all the control always goes to the EFTS Part.the date in the input file is of the form

0920 (the date is 090220)
002C

Please let me know where me conversion of date is getting messed up

Sorry folks forgot to add that i am working in SAS Langauge
i need to do it in SAS only.
Thanks
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8119
Location: East Dubuque, Illinois, USA

PostPosted: Thu Mar 12, 2009 9:06 pm    Post subject:
Reply with quote

Why are you using the COMPRESS function? You don't need the statement with the COMPRESS function -- take it out and the code should run fine.

Post a few ACCTDATE and CYCLEDT values so we can see what they are, as printed by SAS.
Back to top
View user's profile Send private message
balaji.edu

New User


Joined: 09 Aug 2008
Posts: 7
Location: Hyderabad

PostPosted: Thu Mar 12, 2009 9:15 pm    Post subject:
Reply with quote

Input parmcard
Code:
INPUT               
      @1 CYCLEDT  8.
      @3 CYCLEYY  2.




i gave te following code to print the date filds in th SAS List

Code:
DATA PROD1;                                     
   INFILE INLAWS;                               
   INPUT  @125 ODS_I4_DDT PD4.0;                 
ACCTDATE = INPUT(PUT(ODS_I4_DDT,Z6.),YYMMDD6.); 
 CYCLEDT3 = CYCLEDT;                             
 CYCLEDT2=MDY(CYCLEMM,CYCLEDD,CYCLEYY);         
 FORMAT CYCLEDT2 YYMMDD6.;                       
                                               
PROC PRINT DATA=PROD1;                           

without the ccompress statmeent it shows this output

Code:
 ODS_                                   
I4_DDT    ACCTDATE    CYCLEDT3    CYCLEDT
90220     -18577                                                         
90220     -18577                                                         
90224     -18573                                                     
90224     -18573 

with the compress statement

Code:
 ODS_                                   
I4_DDT    ACCTDATE    CYCLEDT3    CYCLEDT
90220      90220                 
90220      90220                 
90224      90224                 
90224      90224                 


in the Sas Log i got the follwing message

Variable CYCLEDT is uninitialized.
Variable CYCLEMM is uninitialized.
Variable CYCLEDD is uninitialized.
Variable CYCLEYY is uninitialized.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8119
Location: East Dubuque, Illinois, USA

PostPosted: Thu Mar 12, 2009 9:35 pm    Post subject:
Reply with quote

1. SAS dates are always stored internally as the number of days since January 1, 1960. A negative sign means days before that date, positive means days after.

2. -18577 in SAS means February 20, 1909. It does not mean February 20, 2009.

3. If you are comparing February 20, 1909 to February 20, 2009 they are not going to be equal.

4. Uninitialized values in SAS are usually important -- in this case (as in most cases) it means your code is not correct.

5. There is a SAS option called YEARCUTOFF that you might want to verify (PROC OPTIONS) to see how it is set.

6. Your code needs more interaction between the DATA steps. I would expect to see something like this in your code and are not seeing it:
Code:
DATA RUNDATE;
INFILE DATEFILE ;
INPUT @1 CYCLEDT  8.
      @3 CYCLEYY  2.

DATA PROD1;                                     
    IF _N_ = 1 THEN SET RUNDATE;
    RETAIN CYCLEDT;
   INFILE INLAWS;                               
   INPUT  @125 ODS_I4_DDT PD4.0;                 
ACCTDATE = INPUT(PUT(ODS_I4_DDT,Z6.),YYMMDD6.);

IF ACCTDATE = CYCLEDT ....
Back to top
View user's profile Send private message
balaji.edu

New User


Joined: 09 Aug 2008
Posts: 7
Location: Hyderabad

PostPosted: Thu Mar 12, 2009 10:08 pm    Post subject:
Reply with quote

this is simplified SAS to i eam executing to print ans see the two dates which i am was comparing .I was retaing the varable in the begining of the SAS.

DATA _NULL_;
RETAIN CYCLEDT 0
CYCLEYY 0
CYCLEMM 0
CYCLEDD 0;

INFILE DATECARD;

IF _N_ = 1 THEN DO;
INPUT
@1 CYCLEDT 8.
@3 CYCLEYY 2.
@5 CYCLEMM 2.
@7 CYCLEDD 2.;
IF CYCLEDT = . THEN ABORT ABEND 16;
END;

DATA PROD1;
RETAIN CYCLEDT;
INFILE INLAWS;
INPUT @125 ODS_I4_DDT PD4.0;

ACCTDATE = INPUT(PUT(ODS_I4_DDT,Z6.),YYMMDD6.);
ACCTDATE = COMPRESS(PUT(ACCTDATE,YYMMDD8.),'-') ;

CYCLEDT2=MDY(CYCLEMM,CYCLEDD,CYCLEYY);
FORMAT CYCLEDT2 YYMMDD6.;
CYCLEDT2 = COMPRESS(PUT(CYCLEDT2,YYMMDD8.),'-') ;
PROC PRINT DATA=PROD1;


as your mail suggest that the year s wrongly ca;calcuated as 1909 instaetd of 2009 can you please explain what does the compress funstion do to changed is back ot 090220 form.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8119
Location: East Dubuque, Illinois, USA

PostPosted: Thu Mar 12, 2009 10:43 pm    Post subject:
Reply with quote

The COMPRESS is not required because you are putting the date as YYMMDD8. (which includes dashes); you would better be served by using YYMMDDN8. which puts out the year as 4 digits but has no dashes in the date.

Try this:
Code:
DATA RUNDATE;
INFILE DATECARD;
INPUT
@1 CYCLEDT 8.
@3 CYCLEYY 2.
@5 CYCLEMM 2.
@7 CYCLEDD 2.;
IF CYCLEDT = . THEN ABORT ABEND 16;

DATA PROD1;
IF _N_ = 1 THEN SET RUNDATE;
RETAIN CYCLEDT;
INFILE INLAWS;
INPUT @125 ODS_I4_DDT PD4.0;

ACCTDATE = INPUT(PUT(ODS_I4_DDT,Z6.),YYMMDD6.);
ACCTDATE = COMPRESS(PUT(ACCTDATE,YYMMDD8.),'-') ;

CYCLEDT2=MDY(CYCLEMM,CYCLEDD,CYCLEYY);
FORMAT CYCLEDT2 YYMMDD6.;
CYCLEDT2 = COMPRESS(PUT(CYCLEDT2,YYMMDD8.),'-') ;
PROC PRINT DATA=PROD1;
FORMAT ACCTDATE YYMMDD10. CYCLEDT YYMMDD10. ;
Back to top
View user's profile Send private message
balaji.edu

New User


Joined: 09 Aug 2008
Posts: 7
Location: Hyderabad

PostPosted: Fri Mar 13, 2009 9:51 am    Post subject:
Reply with quote

The follwin g code i givinig a SA error of
NOTE: The SAS System stopped processing this step because of errorThis may cause NOTE: No observations in data set
NOTE: SAS set option OBS=0 and will continue to check statements.
When this step was stopped there were 0 observations and 49 variables.

DATA RUNDATE;
INFILE DATECARD;

INPUT
@1 CYCLEDT 8.
@3 CYCLEYY 2.
@5 CYCLEMM 2.
@7 CYCLEDD 2.;
IF CYCLEDT = . THEN ABORT ABEND 16;

IF _N_ = 1 THEN SET RUNDATE;
RETAIN CYCLEDT;

CYCLEDT2=MDY(CYCLEMM,CYCLEDD,CYCLEYY);
FORMAT CYCLEDT2 YYMMDD6.;
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Mar 13, 2009 2:20 pm    Post subject:
Reply with quote

Hi,

Can you notice the difference the way code is posted by you and Robert. Please use BBcode when You post some code/error, that's rather readable.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8119
Location: East Dubuque, Illinois, USA

PostPosted: Fri Mar 13, 2009 4:52 pm    Post subject:
Reply with quote

I'm not sure if you're deliberately ignoring what I'm posting or not, but one more time ... based on your earlier posted code, here's what your code should look like:
Code:
DATA RUNDATE;
INFILE DATECARD;

INPUT
@1 CYCLEDT 8.
@3 CYCLEYY 2.
@5 CYCLEMM 2.
@7 CYCLEDD 2.;
IF CYCLEDT = . THEN ABORT ABEND 16;

DATA PROD1;                                     
IF _N_ = 1 THEN SET RUNDATE;
RETAIN CYCLEDT;
   INFILE INLAWS;                               
   INPUT  @125 ODS_I4_DDT PD4.0;                 
ACCTDATE = INPUT(PUT(ODS_I4_DDT,Z6.),YYMMDD6.); 
Note one key difference between the code in your last post and my code: there are two DATA steps in this code, one DATA step in your code. You need two separate DATA steps to accomplish what you appear to be trying to do.

Please copy this code and use it exactly as posted -- do not modify it, do not change it, do not tweak it. I've used this technique hundreds of times so I know it works ... unless somebody modifies it and removes the second DATA step, for example.
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 add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts SUBSTR for Date functions Shaheen Shaik DB2 4 Thu Apr 06, 2017 2:14 pm


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