BookmarkSubscribeRSS Feed
AAP
Calcite | Level 5 AAP
Calcite | Level 5

Hi SAS programmers.

 

I need to do a follow up study on a data set where the dates are only available as year and week stored in the same variable as YYWW (ie 1034 corresponds to 2010 week 34). I would like to covert this variable to a sas date, prefferably to the corresponding monday, however I have had no luck doing so.

I am not very experienced with sas, so the answer might be quite trivial, but I was unable to find the answer using my usual ressources (the little sas book and google).

Hopefully you can help.

 

Kind regards

Alexander

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can use the weeku format, although you will likely need to add the "W" in to get it to work.

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002604468.htm

 

Alternatively, you could use intnx() function, i.e. substr(1,2)=year, then from 01JAN that year intnx("week",substr(3,2)).  To move the date number of weeks forward.

 

data want;
  yywk="1013";
  date1=input(catx("W",substr(yywk,1,2),substr(yywk,3,2)),weeku5.);
  format date1 date9.;
run;
BrunoMueller
SAS Super FREQ

The WEEKx informat requires to have a "W" between the year and the week.

 

So you could use the following code:

data have ;
  week = "1034";
  weekDate = input( cats(substr(week, 1, 2), "w", substr(week, 3, 2)), weekv8.);


  format weekDate weekDate.;
run;

There are various informats, but since you need it to be a Monday use the WEEKV. infromat.

Since you have 2 digist for the year, pay attention to the YEARCUTOFF system option, as this will determine whether it will be 2010 or 1910.

 

Bruno

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1079 views
  • 1 like
  • 3 in conversation