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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1127 views
  • 0 likes
  • 2 in conversation