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

Hi all,

This might be a simple question: I have week and year information, how can I get the corresponding month?

Thanks a lot!

Lizi

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

If you want a date, it being the first date in the given week then you can do something like:

data have;

  year='2013'; week=1; output;

  year='2013'; week=2; output;

  year='2013'; week=3; output;

run;

data want;

  set have;

  if week=1 then new_date=input("01JAN"||strip(year),date9.);

  else new_date=input("01JAN"||strip(year),date9.) + ((week-1) * 7);

  format new_date date9.;

run;

Rembering that a date variable is the number of days since 01Jan1960, so work out the year as 01JAN, gives you the number for that day, then add the week number less 1 (as we want start) multiplied by 7.

View solution in original post

8 REPLIES 8
Quentin
Super User

Can you give a few examples of values you have?  Are they like 201501 for first week of 2015?  201552 for fifty-second week of 2015?  Or some other format?  Also, might need to define what day is the start of the week, etc.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
lizzy28
Quartz | Level 8

Thanks, Quentin.

It was basically two columns:

year week

2013   1

2013   2

...

2013  52

2014   1

2014   2

...

2014  52.

MadhuKorni
Quartz | Level 8

data Want;

input Year week;

Mnt_Name=put(input(cat(0101,Year),ddmmyy10.)+(Week-1)*7,monname3.);

Mnt_Num=Month(input(cat(0101,Year),ddmmyy10.)+(Week-1)*7);

cards;

2013 1

2013 2

2013 16

2013 52

2014 1

2014 2

2014 52

;

proc print;run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

If you want a date, it being the first date in the given week then you can do something like:

data have;

  year='2013'; week=1; output;

  year='2013'; week=2; output;

  year='2013'; week=3; output;

run;

data want;

  set have;

  if week=1 then new_date=input("01JAN"||strip(year),date9.);

  else new_date=input("01JAN"||strip(year),date9.) + ((week-1) * 7);

  format new_date date9.;

run;

Rembering that a date variable is the number of days since 01Jan1960, so work out the year as 01JAN, gives you the number for that day, then add the week number less 1 (as we want start) multiplied by 7.

Quentin
Super User

What would 2015 week 1 mean?  Jan 1, 2015 was a Thursday.  So what is the corresponding month for week 1, January?

What would be the first week number of 2015 that would map to February?  What's the rule that says which month a year-week number should map to?

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
arodriguez
Lapis Lazuli | Level 10

Hi Liziwu,

You must specify what do you need, a desired output maybe.

What do you need, the month at the begining of the week, at the end, the week is in the month if there are 4 or more days on it?

slchen
Lapis Lazuli | Level 10

data Want;

input Year week;

month=month(intnx('week',mdy(1,1,year),week));;

cards;

2013 1

2013 2

2013 16

2013 52

2014 1

2014 2

2014 52

;

Ksharp
Super User

Check informat  WEEKU. WEEKV. WEEKW. 

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
  • 8 replies
  • 1178 views
  • 6 likes
  • 7 in conversation