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

SAS Comparing a Packed decimal date and normal date


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 12, 2009 9:06 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 12, 2009 9:35 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 12, 2009 10:43 pm
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
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

Superior Member


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

PostPosted: Fri Mar 13, 2009 2:20 pm
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Mar 13, 2009 4:52 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Return codes-Normal & Abnormal te... JCL & VSAM 7
Search our Forums:

Back to Top