BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello All,

I use the code:-

proc ttest data=single;
class Place
var Time;
where Place IN('New York','Toronto');
run;
the output that I get gives time in SAS time (for e.g. the Mean Time of New York is 8060). Is it possible to apply a format statement here so as to have time in format "hh:mm:ss" The data set "single" has the variable Time in this format, isnt it ideally true that when t test is applied on a variable from the dataset with time in a given format works for the t test as well.

If it does not work, then kindly could anyone suggest me where the format statement fits in Proc t test?

Kind Regards,
Kriti
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi
Have you tried a FORMAT statement in PROC TTEST??? Normally FORMAT used Inside a PROC step will cause the format to be used for the display of the variables listed. A FORMAT statement goes anywhere between the PROC statement and the RUN or QUIT statement.

The general use of the statement is:
[pre]
format varname fmtname.; (for numeric vars)
Or
format varname $fmtname.; (for char vars)
[/pre]

It should be easy to find a time format or a date/time format by searching on support.sas.com for the topic "formats by category"

Cynthia
deleted_user
Not applicable
Hi Cynthia,

there is one issue that is not very clear and that is if I use format in the Proc t test, given that i get mean values as well fior the analysis variable, is it possible to have these values in the time format as well, or does SAS treat the output of the Proc t test like the mean, standard deviation, min. & max. vlaues of the variable on w format is applied as different so that it is not possible to have these output in proper format.

For example, if I want to test if there is significant difference in the mean time between two different places , then is it possible to have the mean values in time format.

So if I use the code:--

proc ttest data=one;
class PLACE;
format time8.;
where PLACE IN('New York','Toronto');
var time;
run;

then the mean values that I get for the two places will not be in time format..

Kind Regards,
Kriti
Cynthia_sas
SAS Super FREQ
Hi:
You said you wanted to apply a format to your CLASS variable. TIME is not your CLASS variable -- you have TIME on the VAR statement, so it is an ANALYSIS variable. I do not believe you can apply a format to the calculated statistics with a FORMAT statement.

The FORMAT statement in your code is incorrect if you want to apply a format to the CLASS variable. That syntax would be:
[pre]
format PLACE $fmtname.;
[/pre]

You might want to read the documentation on working with DATE and DATETIME and TIME variables. It may not be appropriate to format all the calculated statistics with time formats, depending on what your dates/times represent -- as described in this Tech Support note:
http://support.sas.com/techsup/technote/ts668.pdf

Since a time-based variable represents the number of seconds since midnight (or the number of seconds before or after midnight on Jan 1, 1960 if you have a DATE/TIME variable), you might want to pay special attention to the implications of this information from the above Tech Support document:

[quote]
SAS times are a count of the number of seconds since midnight. They can and often do contain decimal values representing fractions of a second. The range of values is 0 <= sas time < 86400. A SAS time variable having a value of 60 is 1 minute after midnight. 12:00 noon would be stored internally as 43200. midnight is stored as 0. If a SAS time variable has a value larger than 86400, different formats treat the value differently.

[endquote]

It might be OK to format the calculated MIN and MAX with the TIME format, but it may or may not be appropriate to format the MEAN or STDDEV or STDERR with a TIME format.

One thing you can do is capture the output from PROC TTEST in a SAS dataset and then use PROC PRINT to print the numbers using the format that is most appropriate. The other alternative is to change the table template used for PROC TTEST -- this is probably the more complicated approach and would require a steep learning curve compared to PROC PRINT.

To save the output with MIN, MAX and MEAN from PROC TTEST, use the ODS OUTPUT statement. I believe the output object of interest is the STATISTICS output object. The program below shows how to create an output object from the TTEST procedure. The ODS TRACE statement puts output object information into the SAS log -- if the STATISTICS output object is not the one you want, then you can examine the other output objects using similar syntax, once you pick the output object name of interest.

cynthia

[pre]
ods trace on / label;
ods output statistics=work.tstat;
proc ttest data=one;
class PLACE;
var time;
run;
ods trace off;

proc contents data=work.tstat;
title 'What is in the Output dataset';
run;

proc print data=work.tstat;
title 'Use the appropriate format here';
format mean minimum maximum time8.;
run;

[/pre]
art297
Opal | Level 21
I agree with Cynthia that you have provided conflicting information regarding what you want to format. Presuming that you want to format the dependent variable, one way you can do that is by modifying the template.

Some fairly simple examples are provided at:
http://www.ssc.wisc.edu/sscc/pubs/4-8.htm

Like Cynthia said, though, it might not make sense for all of the measures, but might for obtaining the mean time.

HTH,
Art

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 685 views
  • 0 likes
  • 3 in conversation