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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 269 views
  • 0 likes
  • 3 in conversation