BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

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?

 

11 REPLIES 11
thanikondharish
Calcite | Level 5

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

Jagadishkatam
Amethyst | Level 16

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
thanikondharish
Calcite | Level 5
i asked
is there any format for second
Jagadishkatam
Amethyst | Level 16
not, as of I remember
but definitely may be if others can help you.
Thanks,
Jag
error_prone
Barite | Level 11

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 @Kurt_Bremser

Kurt_Bremser
Super User

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).

Reeza
Super User

@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;
Ksharp
Super User
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;
Ksharp
Super User
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1517 views
  • 2 likes
  • 6 in conversation