Using appropriate SAS DATE functions and maybe PROC FREQ, find a frequency table containing the number of Sundays (1), Mondays (2), ...., Saturdays (7) in the year 2017. You can enter your data/dates in any format you want.
Homework, eh?
I think homework questions are fine. But as with any other question, it's important for you to two show what code you have tried, and describe how your code failed (errors in the log? incorrect results?) By posting your code, people can identify the error your made and help you understand the error (and correct it). By posting your code, you help people help you.
this is what I have so far, but we are having troubles getting the days of the week for 2017
I attached some of our results as well
(this does not run)
In the interests of full disclosure (and not wanting to commit plagiarism) I found this answer on stackoverflow https://stackoverflow.com/questions/40676721/number-of-sundays-between-two-dates
data _null_;
format a b date9.;
a='01 nov 2016'd;
b='18 nov 2016'd;
Sundays = intck('weekday234567w',a,b);
put _all_;
run;
Just note that when using the INTCK function to count a particular day-of-week, the "from" date should be the day before the actual start of interval.
Consider '03jan2016'd and '10jan2016'd which are both Sunday, so for that date range you would want N_SUN=2. But
start='03jan2016'd;
end='10jan2016'd;
n_sun=intck('week.1',start,end) ==> 1 (not 2)
or identically
n_sun=intck('weekday234567w',start,end) = 1
so use
n_sun=intck('week.1',start-1,end)
The INTCK('week',from_date,to_date) will count the number of saturday/sunday boundaries crossed between from_date through to_date.
So consider;
n_sun2017=intck('week','31dec2016'd,'31dec2017'd);
or equivalently use the "week.1" interval descriptor.
n_sun2017=intck('week.1','31dec2016'd,'31dec2017'd);
Number of Monday's? Then you need to count the number of sun/mon boundaries, so use the "week.2" interval descriptor:
n_mon2017=intck('week.2','31dec2016'd,'31dec2017'd);
Try this.....
data HAVE;
start='01jan2016'd; end='31dec2016'd; output;
start='01jan2017'd; end='31dec2017'd; output;
run;
data want;
set have;
sunday=0;
do i=start to end;
sunday=ifn(weekday(i)=1, sum(sunday,1),sunday);
retain sunday;
end;
run;
Hope this helps.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.