BookmarkSubscribeRSS Feed
eunkisoo
Calcite | Level 5

My data contains a variable time as minutes (for example, 121). After I calculate average time(PROC MEANS; Var time), I wonder how to convert the average of time to HH:MM(for example 2:01) in the output.

 

3 REPLIES 3
PGStats
Opal | Level 21

 

sasTime = hms(0, myMinutes, 0);
format sasTime hhmm.;
PG
eunkisoo
Calcite | Level 5

Thanks! I applied your tip as in below to print out the mean sleep time by year, sex and age. Is this an efficient way to acquire mean sleep time by year sex and age?

 

Data test(keep=year sex age10 sleep);
  set timeuse;
run;
Proc means data=test ;
  class year sex age10;
  var sleep;
  output out=test1
  mean= mean(sleep)=MeanSleep;
run;

Data test2;
  set test1;

  AveSleep = hms(0, MeanSleep, 0);
  format Avesleep hhmm.;

run;
Proc print data=test2;
  var year sex age10 AveSleep;
run;

ballardw
Super User

I would probably use:

Proc means data=timeuse;

insted unless you have a real good reason for the set test. Note that when you use Proc means (or Summary) the only variables that appear in the output are the class and by (if used) variables, the requested statistics and automatic variables _freq_ and _type_. So the Keep dataset option really doesn't come into play.

 

This code:

Proc means data=test ;
  class year sex age10;
  var sleep;
  output out=test1
  mean= mean(sleep)=MeanSleep;
run;

Is a bit redundant. Your output would have two variables, sleep and MeanSleep, with the same value. If you don't want the variable sleep with the value the mean remove the mean= bit on the output statement.

Also there would not be any problem with using:

MeanSleep= hms(0, MeanSleep, 0); unless you actually need a value in minutes and another in seconds (which is what the HMS conversion does.

I would likely add a label to indicate that the value is actually a duration or interval and not a time of day in case you don't use the data set for awhile and forget.

Something like:

Label AveSleep = "Average sleep duration";

It is a good idea to post code in a code box opened with the forum {i} icon in the menu bar. The main message boxes can reformat your code and sometimes make it hard to read. Also sometimes html artifacts appear in code when copying from teh main window which can cause errors for people running example code to test.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3138 views
  • 1 like
  • 3 in conversation