×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

(OP)
I'm having some problems writing out a timestamp field.  The format that I was aiming for was YYYY-MM-DD-HH:MM:SS.ssssss.

The informat used to read in the data was TODSTAMP4..  Here are some samples of my output using a PUT statement:

CODE

NO FORMAT               DATETIME23.6             TIME12.                  YYMMDD10.
1586273562.1            07APR10:15:32:42.148864  440631:32:42             **********
1583555017.7            07MAR10:04:23:37.719808  439876:23:38             **********
1584883864.5            22MAR10:13:31:04.453120  440245:31:04             **********
1583945561.9            11MAR10:16:52:41.948160  439984:52:42             **********
1588176606              29APR10:16:10:05.954048  441160:10:06             **********
1584637555              19MAR10:17:05:54.999296  440177:05:55             **********
1588271341.6            30APR10:18:29:01.649920  441186:29:02             **********
1588708670.2            05MAY10:19:57:50.193664  441307:57:50             **********
1584465774.1            17MAR10:17:22:54.133248  440129:22:54             **********

Can anyone suggest how to get the format into YYYY-MM-DD-HH:MM:SS.ssssss?

Thanks in advance!

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

You can create the string yourself by concatinating two formats.
Here is how:

CODE

data _null_;
  x=datetime();*** or any datetime value ***;
  y=put(datepart(x),yymmdd10.);
  z=put(timepart(x),time16.6);
  newtime=trim(y)||'-'||trim(left(z));
  put x= y= z= newtime=;
run;

Hope this helps you.
Klaz

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

(OP)
Hi Klaz ... thank you for the response!

I will give this a try.  Can you offer any insight as to why when using the YYMMDD10. format the data is displayed with all asterisks?

Thank you again!

KS

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

SAS does that when it doesn't have enough room to print the whole value.  If you want to display the numeric value as that format you need to only supply the date portion.

CODE

y=datepart(yourfulldatetimevalue);
format y yymmdd10.;

Klaz

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

(OP)
Makes sense, thanks again Klaz!  smile

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

(OP)
Hi Klaz ... I tried the following but am getting an error:

CODE

1            OPTIONS          OBS=102 FIRSTOBS=1;               
2            DATA R001;                                         
3            INFILE INPUT1;                                     
4            FILE SYSOUT;                                       
5                                                               
6            INPUT @01 RECTYP $CHAR1. @ ;                       
7              IF RECTYP = '1' THEN                             
8                DO;                                            
9                  INPUT @73 ED_200_BASE1_EFF_DATE TODSTAMP4.;  
10               END;                                           
11                                                              
12             X=DATETIME(ED_200_BASE1_EFF_DATE);               
                 ________                                       
                 ________                                       
                 ________                                       
                 72                                             
                 72                                             
                 72                                             
ERROR 72-185: The DATETIME function call has too many arguments.
ERROR 72-185: The DATETIME function call has too many arguments.
ERROR 72-185: The DATETIME function call has too many arguments.

I assumed hte DATETIME function would be used on the variable I'm reading it.  I checked the Language Dictionary and it indicates that I may need to only use the () to grab the current time.  Is this correct?  If so, how would I get the value from my input variable?

Any suggestions?

Thank you again!

ks

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

(OP)
Hi Klaz ... just an update.  I tried the following and it works:

CODE

Y=PUT(DATEPART(ED_200_BASE1_EFF_DATE),YYMMDD10.);               
Z=PUT(TIMEPART(ED_200_BASE1_EFF_DATE),TIME16.6);                
  IF HOUR(ED_200_BASE1_EFF_DATE) LT 10 THEN SUBSTR(Z,1,1) = '0';
ED_200_BASE1_EFF_DATE_C=TRIM(Y)||'-'||TRIM(LEFT(Z));            
    
PUT Y= Z= ED_200_BASE1_EFF_DATE_C= ;                            

I added an IF statement since I need the hour to be a two-digit number.  However, I'm getting a space between my hour digits:

CODE

Y=2010-03-07 Z=0 4:23:37.719808 NEWTIME=2010-03-07-0 4:23:37.719808

Would you have a suggestion on where I can get rid of this space?

ks

RE: Formatted Datetimestamps from TODSTAMPw. Informat Not Correct

I found an easier way for you to get your datetime string value.
I presume that you will have a SAS datetime value to work with. Well then use the ISO 8601 format for date and time..

CODE

newdatetimevalue=translate(put(x,IS8601DT26.6),'-','T');

'x' is your datetime value and I use the TRANSLATE function to swap the ISO's standard 'T' sepparator for your '-' (hyphen requirement)

Good luck!
Klaz

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close