I used code to develop a table that essentially tallies the number the count of people in an area in a given hour. I would like the divide the Day of the Week number columns in the table by an arbitrary number. For example, I would like to divide each individual cell (12am to 11pm) in Day of the Week column 1 by 5 (so 140/5, 141/5, 122/5 etc.); for Day of the Week column 2, I would like do to the same to each hour cell but by 4 instead of 5. Is the possible?
data ED_TAT2;
set ED_TAT1;
counttime = round(checkin_date_time,3600);
format counttime datetime18.;
do while (counttime le round(dispo_date_time,3600) );
hr = timepart(counttime);
day = weekday(datepart(counttime));
date = datepart(counttime);
output;
counttime= intnx('hour',counttime,1,'B');
end;
run;
proc tabulate data=ED_TAT2;
class hr day;
format hr timeampm5. ;
table hr='', day*n='' / box=hr;
label hr='Hour'
day= 'Day of week';
run;
Something like ths perhaps?
data ED_TAT2;
set ED_TAT1;
counttime = round(checkin_date_time,3600);
format counttime datetime18.;
do while (counttime le round(dispo_date_time,3600) );
hr = timepart(counttime);
day = weekday(datepart(counttime));
date = datepart(counttime);
weight = 1/choosen(day, 5, 4, 3, 2, 1, 1, 1);
output;
counttime= intnx('hour',counttime,1,'B');
end;
run;
proc tabulate data=ED_TAT2;
class hr day;
var weight;
format hr timeampm5. ;
table hr='', day*sum=''*weight='' / box=hr;
label hr='Hour'
day= 'Day of week';
run;
Something like ths perhaps?
data ED_TAT2;
set ED_TAT1;
counttime = round(checkin_date_time,3600);
format counttime datetime18.;
do while (counttime le round(dispo_date_time,3600) );
hr = timepart(counttime);
day = weekday(datepart(counttime));
date = datepart(counttime);
weight = 1/choosen(day, 5, 4, 3, 2, 1, 1, 1);
output;
counttime= intnx('hour',counttime,1,'B');
end;
run;
proc tabulate data=ED_TAT2;
class hr day;
var weight;
format hr timeampm5. ;
table hr='', day*sum=''*weight='' / box=hr;
label hr='Hour'
day= 'Day of week';
run;
Amazing, works perfectly!
Somewhat new to SAS, are you aware a good resource where I can learn how your answer works, for example-I want to figure out how ' weight = 1/choosen(day, 5, 4, 4, 4, 4, 5, 5)' and 'days*sum=''*weight=''' work their magic.
There is no magic. It's all in the SAS documentation
CHOOSEN function
PROC TABULATE; TABLE statement
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.