BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aman4SAS
Obsidian | Level 7

can we get the dates of all sunday for given year??????

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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

Thanks,
Jag

View solution in original post

6 REPLIES 6
Peter_C
Rhodochrosite | Level 12

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?

Keith
Obsidian | Level 7

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;

Aman4SAS
Obsidian | Level 7

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,

Jagadishkatam
Amethyst | Level 16

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

Thanks,
Jag
Aman4SAS
Obsidian | Level 7

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,

Jagadishkatam
Amethyst | Level 16

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

Thanks,
Jag

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

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
  • 6 replies
  • 867 views
  • 3 likes
  • 4 in conversation