Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatted Datetimestamps from TODSTAMPw. Informat Not Correct 1

Status
Not open for further replies.

ks01

MIS
Aug 11, 2002
110
US
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!
 
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
 
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
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top