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;
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;
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;
Thank you.
Does it meet your need? Accept as a solution.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.