DATA Step, Macro, Functions and more

how to show seconds format

Reply
Frequent Contributor
Posts: 84

how to show seconds format

data want ;

time='12:12:34't ;

format time time8. ;

run;

 

proc print data=want ;

format time second. ;

run;

 

 

 

If i run above program it doesn't show the value so what will we do?

 

Super User
Posts: 10,570

Re: how to show seconds format

Posted in reply to thanikondharish

Maxim 1 & Maxim 2.

 

From where do you get the notion that a "second" format exists?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 10,570

Re: how to show seconds format

Posted in reply to thanikondharish

What is a SAS time value?

See here: http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p1wj0wt2ebe2a0n1lv4l...

This will give you a clue.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 84

Re: how to show seconds format

Posted in reply to thanikondharish

i want to show only seconds on output by using proc pirnt

Trusted Advisor
Posts: 1,163

Re: how to show seconds format

Posted in reply to thanikondharish

we could show the seconds in a new variable using the second function, not sure if we have a format for seconds only

 

please try the below code which will create a new variable with seconds.

 

data want ;
time='12:12:34't ;
second=second(time);
run;
Thanks,
Jag
Frequent Contributor
Posts: 84

Re: how to show seconds format

Posted in reply to Jagadishkatam
i asked
is there any format for second
Trusted Advisor
Posts: 1,163

Re: how to show seconds format

Posted in reply to thanikondharish
not, as of I remember
but definitely may be if others can help you.
Thanks,
Jag
Regular Contributor
Posts: 226

Re: how to show seconds format

Posted in reply to thanikondharish

Do you need the seconds-part from the time-value or the time-value in seconds?

 

If you need the later: Have you read the documents linked by @KurtBremser

Super User
Posts: 10,570

Re: how to show seconds format

Posted in reply to thanikondharish

Once again: read the documentation. Time values ARE seconds, so no special format is needed. If you need to extract the seconds within a minute, use the second() function, or mod(time,60).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 24,003

Re: how to show seconds format

Posted in reply to thanikondharish

@thanikondharish wrote:
i asked
is there any format for second

Time values are stored as seconds, so not having any format will display it in seconds. 

Any other format applies a style to it. Similarly, dates as stored as days. 

 

 

data want;
    time='12:12:34't;
    seconds = 34 + 12*60 + 12*60*60; *to check;
    format time time8.;
run;

title 'With time8 format';

proc print data=want;
    format time time8.;
run;

title 'With no format';

proc print data=want;
    format time;
    ;
run;
Super User
Posts: 10,849

Re: how to show seconds format

Posted in reply to thanikondharish
proc format ;
picture fmt
 low-high='%0s' (datatype=time);
run;



data want ;
time='12:12:34't ;
format time time8. ;
run;
proc print data=want ;
format time fmt. ;
run;
Super User
Posts: 10,849

Re: how to show seconds format

Posted in reply to thanikondharish
proc format ;
picture fmt
 low-high='%0s' (datatype=time);
run;



data want ;
time='12:12:34't ;
format time time8. ;
run;
proc print data=want ;
format time fmt. ;
run;
Ask a Question
Discussion stats
  • 11 replies
  • 82 views
  • 2 likes
  • 6 in conversation