BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anandkvn
Lapis Lazuli | Level 10
data wwk;
do weekday ='01-Jan-2019'd to'31-Dec-2019'd ;
 if weekday =1 then output  ;
end;
format weekday date9.;
run;

i want output like 

DATEWeekday
05-01-2019Saturday
05-02-2019Tuesday
05-03-2019Tuesday
05-04-2019Friday
05-05-2019Sunday
05-06-2019Wednesday
05-07-2019Friday
05-08-2019Monday
05-09-2019Thursday
05-10-2019Saturday
05-11-2019Tuesday
05-12-2019Thursday
1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Anandkvn 

 

Try this. It is a bit more effecient, as it loops over months and not over days (12 vs. 365).

 


data wrk (drop=start end i);
	format date ddmmyyd10.;
	start = '01-Jan-2019'd;
	end = '31-Dec-2019'd ;
	do i = 0 to intck('month',start,end);
		Date = intnx('month',start,i)+4;
		Weekday = left(put(date,downame.));
		output;
	end;
run;

 

View solution in original post

4 REPLIES 4
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Anandkvn 

 

Try this. It is a bit more effecient, as it loops over months and not over days (12 vs. 365).

 


data wrk (drop=start end i);
	format date ddmmyyd10.;
	start = '01-Jan-2019'd;
	end = '31-Dec-2019'd ;
	do i = 0 to intck('month',start,end);
		Date = intnx('month',start,i)+4;
		Weekday = left(put(date,downame.));
		output;
	end;
run;

 

Jagadishkatam
Amethyst | Level 16
data wwk;
do date ='01Jan2019'd to'31Dec2019'd ;
 if day(date) =5 then output  ;
 weekday=weekday(date);
end;
format date date9. weekday DOWNAME9.;
run;
Thanks,
Jag
Anandkvn
Lapis Lazuli | Level 10

Hi

 Jagadish not getting desired output as per 2019 year 

ShiroAmada
Lapis Lazuli | Level 10

Make it simpler using MDY function and a do loop.

 

data high_five;
  do year=2019 to 2020;
    do month=1 to 12;
	  weekday=mdy(month,5,year);
	  format weekday date9.;
	  output;
	end;
  end;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1052 views
  • 0 likes
  • 4 in conversation