View previous topic :: View next topic
|
Author |
Message |
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
Hi,
Iam having trouble in formatting date in Packed Decimal whihc is 2003073. I need to convert this date into MMDDYYYY format.
When i tried using "PUT" and "INPUT" instructions it was giving an invalid date as 03/25/7444.
If you have any idea please let me know...... |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Code: |
INPUT @01 DATEIN PK4.;
DATEXX = INPUT(PUT(DATEIN,$8.),YYMMDD8.);
|
Puts the PK4. value from the input into the SAS base date format, so you can then play around with a new output format. |
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
I have tried with this but it was shoeing this error:
INPUT @42 RIN_SYSDT PK4.;
SYS_DATE = INPUT(PUT(RIN_SYSDT,$8.),MMDDYY8.);
Variable RIN_SYSDT has already been defined as numeric.
FORMAT SYS_DATE MMDDYY10.;
Thank You |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
This is what I get
Code: |
3 DATA OUT01;
4 INFILE DATEFILE;
5 INPUT @01 DATEIN PK4.;
6 DATEXX = INPUT(PUT(DATEIN,$8.),YYMMDD8.);
WARNING: Variable DATEIN has already been defined as numeric.
7 FORMAT DATEXX MMDDYY10.;
Followed by the output of PROC PRINT ..............
The SAS System
DATEIN DATEXX
20071101 11/01/2007
|
|
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
but for me when i try it was showing incorrect date as:
RIN_SYSDT=2003073 SYS_DATE=. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
try something like this to see the values that get created with each part, and try to see where your error is.
Code: |
DATA OUT01;
INFILE DATEFILE;
INPUT @01 DATEIN PK4.;
DATEXX = PUT(DATEIN,$8.);
DATEYY = INPUT(DATEXX,YYMMDD8.);
PROC PRINT DATA=OUT01 NOOBS;
|
|
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
Please find the below output which i have got for the date formats.
RIN_
SYSDT SYS_DATE
2003073 .
2003133 .
2003209 .
2004076 .
2004162 .
2004313 .
2006199 .
If you observe the field RIN_SYSDT, the first 4 digits are always having year(i.e, 2003,2004,2006 etc). If we convert the remaining 3 digits to month and date then we may be getting the correct format.
Any sugeestions on this?
Thank you, |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Quote: |
INPUT @42 RIN_SYSDT PK4.; |
Can you post the exact hexadecimal data at pos 42 length 4 ? |
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
please find the below data
RIN_SYSDT=2003073
4----+----
7020034444
5C037C0000 |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Ok, so I had set my date up as a Packed UNSIGNED field, and yours is signed, so swap PK4. into PD4.
You then need to put this julian date into SAS base date format and then put it into mmddyyyy format.
Shouldn't be too difficult
Race yah |
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
i have tried with PD4, i was not able to get it..plz help me...
INPUT @42 RIN_SYSDT PD4.;
SYS_DATE = INPUT(PUT(RIN_SYSDT,$8.),MMDDYY8.);
FORMAT SYS_DATE MMDDYY10.; |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
You will need to look at the various date functions of SAS to convert one date format into another.
I have told you above what I would do, but unfortunately do not have the time to do both our jobs. As I get paid for mine - it sort of gets preference.
Quote: |
You then need to put this julian date into SAS base date format and then put it into mmddyyyy format. |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
vasantha: what you need is
Code: |
DATEXX = INPUT(DATEIN,JULDATE7.); |
to convert a 7-digit Julian date to SAS format. Once it's a SAS date you can output it in whatever format you want. |
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
Yeah just now i tried to convert it to julian date then to MMDDYY10. format now iam able to see correct date. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Robert, did you test that ......................
Code: |
7 DATEYY = INPUT(DATEIN,JULDATE7.);
_________
_________
_________
48
48
48
ERROR 48-59: The informat JULDATE was not found or could not be loaded.
ERROR 48-59: The informat JULDATE was not found or could not be loaded.
ERROR 48-59: The informat JULDATE was not found or could not be loaded.
|
|
|
Back to top |
|
|
vasantha
New User
Joined: 05 Aug 2008 Posts: 16 Location: hyderabad
|
|
|
|
try giving datejul... |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
vasantha wrote: |
try giving datejul... |
Exactly ..........
I hate SAS date formats and playing around changing them, but after some little testing .........
DATEXX = PUT(DATEJUL(DATEIN),MMDDYY10.);
Using the DATEJUL function, DATEIN is converted to a SAS base date, and that value is then PUT into the required format. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
JULDATE, DATEJUL ... one of them things! I didn't get a chance to test my code since I'm in class this week and not anywhere close to a mainframe. At least the problem got resolved. |
|
Back to top |
|
|
|