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

Write Timestamp into output file. - SAS


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Sun May 20, 2012 5:34 pm
Reply with quote

Hi,
I have a timstamp value inside a SAS dataset variable.
I would like to write it to an external PS file using PUT statement in the original format.

Code:
data timestamp;
infile 'dcollect.file';
input @13 timestmp SMFSTAMP8. ;
run;

<some processing comes here.>

data _null_;
set timestamp;
file 'some external file';
put @13 timestmp ??????; <- what format should i specify?
run;


Please let me know how we write the timestamp variable to external file in the same format in which it was read in the 1st step.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sun May 20, 2012 10:17 pm
Reply with quote

Did you try SMFSTAMP8. ?
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Sun May 20, 2012 10:22 pm
Reply with quote

Yes, It gave the error,
Code:

ERROR 48-59: The format SMFSTAMP was not found or could not be loaded.


I think SMFSTAMP is one of those things like $CHAR which are only informats used in INPUT statement but cannot be used in PUT statement.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sun May 20, 2012 10:34 pm
Reply with quote

Yeah, looking at the SAS documentation, SMFSTAMP is an INFORMAT -- which means it cannot be used for output. But you might be able to use PD8. to put the value back out.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon May 21, 2012 12:27 pm
Reply with quote

Hi Robert,
Thanks for the suggestion.
I tried the PD and PIB formats, but it looks like timestamp read via SMFSTAMP8. is something different.
Code:

OPTIONS OBS = 10;   
DATA READSTAMP;             
 INFILE 'dcollect file';
 INPUT @13 TIMESTMP SMFSTAMP8.;   
 FILE 'WELLS.SORTIN';   
 PUT @13 TIMESTMP PIB8. @25 TIMESTMP PD8.;
RUN;   
       
DATA VERIFY;       
 INFILE 'WELLS.SORTIN';         
 INPUT @13 TIMSTMP1 SMFSTAMP8. @25 TIMSTMP2 SMFSTAMP8.;   
 PUT TIMSTMP1 DATETIME19. TIMSTMP2 DATETIME19.;       
RUN;   

Error:
NOTE: Invalid data for TIMSTMP1 in line 1 13-20. 
NOTE: Invalid data for TIMSTMP2 in line 1 25-32. 


I will try to search and see what format the data is originally stored in raw file.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon May 21, 2012 2:36 pm
Reply with quote

Thinking about it, I suspect SAS converts an SMFSTAMP value into a date/time value, which would be useless to output -- and difficult to translate. When I get a chance later on today, I'll see if I can come up with something reasonably straightforward to handle it.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon May 21, 2012 4:39 pm
Reply with quote

Quote:
I suspect SAS converts an SMFSTAMP value into a date/time value, which would be useless to output

Yes correct, it makes no sense to write sas datetime values in PD or IB formats. My bad, It did not occur to me.
Quote:
I'll see if I can come up with something reasonably straightforward to handle it.

I too will continue to search for a solution. Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon May 21, 2012 5:38 pm
Reply with quote

Suspicion confirmed. You can use something like this against an SMFSTAMP8 variable DTTM:
Code:
     CENT     = INT((YEAR(DATEPART(DTTM)) - 1900) / 100) ;
     YRVAL    = JULDATE(DATEPART(DTTM)) ;
     OUTVAL   = CENT * 100000 + YRVAL ;
     TM       = TIMEPART(DTTM) * 100  ;
     FORMAT TM IB4. OUTVAL PD4. ;
and output TM and OUTVAL which together will be the SMFSTAMP8. value.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon May 21, 2012 5:43 pm
Reply with quote

Works GREAT.!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon May 21, 2012 6:03 pm
Reply with quote

Good to hear that.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon May 21, 2012 10:10 pm
Reply with quote

Condensed ur code a little bit,
Code:
TM = TIMEPART(DTTM) * 100;             
OUTVAL = JULDATE(DATEPART(DTTM)) - 1900000;
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue May 22, 2012 2:16 am
Reply with quote

Yeah, the code I posted is designed to show what's happening, not be the most condensed. You don't want to have to make a change in 4 years and look at that code saying "Why 1900000?"
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Tue May 22, 2012 2:56 pm
Reply with quote

Robert, I understood that you were explaining things in detail, when you posted your code.
Quote:
make a change in 4 years and look at that code saying "Why 1900000?"

4 years? nah.. my retention period is 3-4 months.
I can't concentrate on a thing for more than 2... oh look, a cookie
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Wed May 30, 2012 12:30 pm
Reply with quote

I guess the next code (without any additional processing) would work :


Code:

data timestamp;
infile 'dcollect.file';
input @13 timestmp $CHAR8.;  /* <---------------- */
run;

<some processing comes here.>

data _null_;
set timestamp;
file 'some external file';
put @13 timestmp $8.;  /*------------------- */
run;
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Wed May 30, 2012 1:16 pm
Reply with quote

Hi Peter,
Thanks for your thoughts.
But in my case, the limitation is I will not be able to change the way the timestamp is read in the first step. It is read using SMFSTAMP. informat internally.

The below step was for describing the problem.
Code:
data timestamp;
infile 'dcollect.file';
input @13 timestmp SMFSTAMP8. ;
run;

Robert's technique helped in my case.
Thanks,
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Wed May 30, 2012 2:33 pm
Reply with quote

Vasanth, thought it was a 1 to 1 copy of the field.
With respect to Robert's solution my approach was to do it with with
a minimum of coding.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Wed May 30, 2012 2:41 pm
Reply with quote

Quote:
With respect to Robert's solution my approach was to do it with with
a minimum of coding.

Yup, Got your point.
Having alternate ways of doing the same thing are handy at times. May not be applicable in one scenario, but will be more suited and efficient in other scenarios.
Thanks,
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 3
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top