BookmarkSubscribeRSS Feed
niki0209
Obsidian | Level 7

Hi

 

I have this type of data:

person variable_2020_01 variable_2020_02
A 1 5
B 6 8

 

And I need it transformed into weekly data:

 

person weekly_variable_2020_01 weekly_variable_2020_02 weekly_variable_2020_03 weekly_variable_2020_04 weekly_variable_2020_05 weekly_variable_2020_06 weekly_variable_2020_07 weekly_variable_2020_08
A 1 1 1 1 5 5 5 5
B 6 6 6 6 8 8 8 8

 

I realise that I have two problems:

1) I don't know how to code this in a away that just assumes 4 weeks=1month

2) 4 weeks doesn't always equal 1 month

 

So I am hoping that someone has experience with this dilemma and is able to help me.

Thank a lot! 🙂

2 REPLIES 2
PaigeMiller
Diamond | Level 26

There is no exact unambiguous and clearly agreed upon method of turning months into weeks. If you can state, in words, exactly how you want to do it, we can help code it for you.

 

The whole thing would be easier if months and weeks were stored as data in the variables, instead of having months and weeks stored in variable names.

 

Repeating: please provide data as working SAS data step code (Examples and instructions).

--
Paige Miller
Kurt_Bremser
Super User

Before you do anything else, transform your stupid wide data to intelligent long data, converting the interesting part of the names to SAS date values on the way. Data (dates) does not belong in structure (variable names)!

From there, you can create weekly data rather easily, but first you need to clearly define what a "week" is in your context, e.g starts on Sunday, starts on Monday, or starts on a given day (e.g. the first of a month) using a 7-day interval from there. If a week starts on a fixed weekday, how do you allocate partial weeks to months?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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