BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
LarissaW
Obsidian | Level 7

Screenshot 2024-01-28 054817.png

Hi,

I'd like to know, is there a way to merge data like what is shown in the figure? I have several observations under the same ID. I want to merge data based on both ID and Type. For the new data highlighted in the expected table, 13 is from the length 10+3, and 54 is from the weighted average of the two observations of Type 1 under ID 1 [(10x3+67x10)/(10+3)]. I also have other data in the database that need to be cleaned like this, so I would like to know if there are codes that I can apply to bulk change the structure of the dataset to the expected one.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Why would you want to re-arrange this data at all? What can you do with the wide data set that you cannot do with the long data set?

 

Sums, averages and weighted averages can all be computed from the original data without any re-arranging of the data.

 

proc summary data=have nway;
    class id type;
    var year;
    var dose/weight=year;
    output out=sum_dose sum(year)=year mean(dose)=dose;
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Why would you want to re-arrange this data at all? What can you do with the wide data set that you cannot do with the long data set?

 

Sums, averages and weighted averages can all be computed from the original data without any re-arranging of the data.

 

proc summary data=have nway;
    class id type;
    var year;
    var dose/weight=year;
    output out=sum_dose sum(year)=year mean(dose)=dose;
run;
--
Paige Miller
LarissaW
Obsidian | Level 7

Hi, thank you for your reply. I have to merge it to a single ID because I will merge this data with another database and use the merged dataset to do a Cox proportional analysis. I thought that the Cox model doesn't allow multiple observations with the same ID.

PaigeMiller
Diamond | Level 26

As stated above, you can still do the calculations without re-arranging.

--
Paige Miller
LarissaW
Obsidian | Level 7

I'm still confused. If I want to merge two datasets, I think I should sort the data by ID first. The long data multiple observations with the same ID, then how is it possible to be merged with another dataset? Also, I think each row will be calculated as a sample, so if I have multiple rows with the same ID, the Cox proportional model will miscalculate the wrong categories.

ballardw
Super User

@LarissaW wrote:

I'm still confused. If I want to merge two datasets, I think I should sort the data by ID first. The long data multiple observations with the same ID, then how is it possible to be merged with another dataset? Also, I think each row will be calculated as a sample, so if I have multiple rows with the same ID, the Cox proportional model will miscalculate the wrong categories.


You haven't shown a second data set to involve any "merge". So you need to show that data set as well before any "merge" is discussed. And then what the appearance of that resulting merged data would look like.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 631 views
  • 0 likes
  • 3 in conversation