Help using Base SAS procedures

applying format to the CLASS vraible

Reply
N/A
Posts: 0

applying format to the CLASS vraible

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
SAS Super FREQ
Posts: 8,864

Re: applying format to the CLASS vraible

Posted in reply to deleted_user
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
N/A
Posts: 0

Re: applying format to the CLASS vraible

Posted in reply to Cynthia_sas
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
SAS Super FREQ
Posts: 8,864

Re: applying format to the CLASS vraible

Posted in reply to deleted_user
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]
PROC Star
Posts: 7,471

Re: applying format to the CLASS vraible

Posted in reply to deleted_user
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
Ask a Question
Discussion stats
  • 4 replies
  • 140 views
  • 0 likes
  • 3 in conversation