can we get the dates of all sunday for given year??????
Hi Keith,
A very good code to get all the dates in a year. very well executed. Appreciable.
@Aman4sas,
Keith has given a very good code, just make few changes to the code and it will work the way you want. As per your latest post, you wanted to pull any weekday from the given year. i have made few minor changes to Keith code. like i added an additional macro variable weekday, where you can give the number of the weekday for which you want to get the date (like 1 for sunday,2 for monday etc.,) and changes the do loop to list the days in a year. here i used 2 to retrieve the dates of weekday monday (2).
%let rpt_yr=2012;
%let weekday=2;
data sundays_&rpt_yr.;
format sunday_date date9.;
do i=0 to 366;
sunday_date=intnx('day',"01Jan&rpt_yr."d,i);
if weekday(sunday_date)=&weekday. then output;
end;
drop i;
run;
Thanks,
Jagadish
how would you like the result? - a list in the SASlog, a comma separated list in a macro variable, an output report or a SAS dataset?
Here's a simple piece of code that creates a dataset of all Sundays in a year. The 'week' interval in the INTNX function returns Sunday by default.
%let rpt_yr=2012;
data sundays_&rpt_yr.;
format sunday_date date9.;
do i=0 to 52;
sunday_date=intnx('week',"01Jan&rpt_yr."d,i);
if year(sunday_date)=&rpt_yr. then output;
end;
drop i;
run;
Thanks for ur help sir,, but i m looking for not specific sunday,, any of day of week, like it can b monday ,, i can be friday,, n i m looking result in list view, not together sperated by comma,
Hi Keith,
A very good code to get all the dates in a year. very well executed. Appreciable.
@Aman4sas,
Keith has given a very good code, just make few changes to the code and it will work the way you want. As per your latest post, you wanted to pull any weekday from the given year. i have made few minor changes to Keith code. like i added an additional macro variable weekday, where you can give the number of the weekday for which you want to get the date (like 1 for sunday,2 for monday etc.,) and changes the do loop to list the days in a year. here i used 2 to retrieve the dates of weekday monday (2).
%let rpt_yr=2012;
%let weekday=2;
data sundays_&rpt_yr.;
format sunday_date date9.;
do i=0 to 366;
sunday_date=intnx('day',"01Jan&rpt_yr."d,i);
if weekday(sunday_date)=&weekday. then output;
end;
drop i;
run;
Thanks,
Jagadish
Hi , its nice logic,, n its not near by actually its exact result what i was looking for,,
thanks for ur help.
i beg ur pardon to ask one more ques,, that what is the use of .(dot) which u use after macro variable..as i never used . for that, and it does same work with using .(dot)
%let rpt_yr=2012;
%let weekday=2;
data sundays_&rpt_yr.; -> . after rpt_yr
format sunday_date date9.;
do i=0 to 366;
sunday_date=intnx('day',"01Jan&rpt_yr."d,i); -> . after rpt_yr
if weekday(sunday_date)=&weekday. then output; -> . after weekday
end;
drop i;
run;
i m realy sorry if u thnk its silly que,, but i m realy confused abt it,. what is the logic behind it,
Hi,
if you are using a single macro variable like &rpt_yr then there is no need for you to put any . after the macro variable when you use it. it will work with the .
but there will be scenarios when you will use macro variable before the name of the variable like for example, in those situations if you dont use the . after the macro variable, it will consider the entire name as macro variable and it will search for that macro variable, to avoid that we use . after macro variable.
hope the below example will help you to understand it.
data xname;
set sashelp.class;
run;
%let name=x;
proc print data=&name.name;
run;
Thanks
Jagadish
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.