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

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, 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
  • 3 replies
  • 3340 views
  • 1 like
  • 3 in conversation