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

I am trying to get the Year to go with the value returned for WEEK Function using the 'v' descriptor.  I am compiling data by a 7 day week period and assigning the aggregated data a date of the value returned from the YEAR function and WEEK Function with the 'v' descriptor.  ( YYYY WW ) I have run into an issue with the New Year.  I get the correct WEEK for December 30 and 31 (1st week of Year 2020).  However, I can't figure out how to return the Year 2020 to match the week.  I end up getting 2019 01 as the YYYY WW which is not what I want.  I want it to return as 2020 01.  Any thoughts would be appreciated.

 

options pageno=1 nodate ls=80 ps=64;

title 'Values of the U, V, and W Descriptors';

data a(drop=i date0 date1 y);
date0 = '20dec2019'd;
do y = 1;
 date1 = intnx("YEAR",date0,y,'s');
do i = 0 to 20;
 date = intnx("DAY",date1,i);
year = YEAR(date);
week = week(date);
 week_u = week(date, 'u'); 
 week_v = week(date, 'v'); 
 week_w = week(date, 'w'); 
output;
end;
end;
format date WEEKDATX17.;
run;
proc print; run;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
dcmacedo
Obsidian | Level 7
Use "INTNX" with "Alignment" to get the year of the last "day of the week".
options pageno=1 nodate ls=80 ps=64;

title 'Values of the U, V, and W Descriptors';

data a(drop=i date0 date1 y);
date0 = '20dec2019'd;
do y = 0;
 date1 = intnx("YEAR",date0,y,'s');
do i = 0 to 20;
 date = intnx("DAY",date1,i);
year = YEAR(date);
week = week(date);
year_v = YEAR(intnx("WEEK.2",date,0,"e"));
week_v = week(date, 'v'); 
output;
end;
end;
format date WEEKDATX17.;
run;
proc print;
run;

 

View solution in original post

3 REPLIES 3
dcmacedo
Obsidian | Level 7
Use "INTNX" with "Alignment" to get the year of the last "day of the week".
options pageno=1 nodate ls=80 ps=64;

title 'Values of the U, V, and W Descriptors';

data a(drop=i date0 date1 y);
date0 = '20dec2019'd;
do y = 0;
 date1 = intnx("YEAR",date0,y,'s');
do i = 0 to 20;
 date = intnx("DAY",date1,i);
year = YEAR(date);
week = week(date);
year_v = YEAR(intnx("WEEK.2",date,0,"e"));
week_v = week(date, 'v'); 
output;
end;
end;
format date WEEKDATX17.;
run;
proc print;
run;

 

dcmacedo
Obsidian | Level 7

Does it meet your need? Accept as a solution.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 688 views
  • 0 likes
  • 2 in conversation