BookmarkSubscribeRSS Feed
joannahh
Calcite | Level 5

Hello,

 

I am trying to merge one wide and one long data set. Both datasets have information on the same participants which is identified by the variable ID. 

 

Once I sort the datasets by ID, can I merge them from their original data formats? Or do I have to make both datasets into the same format (both long or both wide files) in order to merge them?

 

I greatly appreciate your help!

 

Best,

Joanna

3 REPLIES 3
Reeza
Super User

@joannahh wrote:

 

 

Once I sort the datasets by ID, can I merge them from their original data formats? Or do I have to make both datasets into the same format (both long or both wide files) in order to merge them?

 

 


You can merge them without changing them to the same structure, as long as the output will be what you want. It's really dependent on what you want as output. 

joannahh
Calcite | Level 5

Thank you so much for your fast response! 

So the following syntax is what I used and my output is in a long file (which is what I wanted): 

"data merged; merge wide long(in = a) ; by ID; if a; run;"

 

 

I'm not sure if I am providing sufficient information for a response but I was wondering if getting a long-file output is what you would expect from the above syntax. 

 

Thank you again for your help!

 

 

 

mkeintz
Jade | Level 19

By "long", I presume you mean a dataset with possible repeats of the by variable ID.  And by "wide" do you mean one observation per ID?

 

If so then your program will be a "LONG left join WIDE on long.id=wide.id" in proc sql syntax.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1865 views
  • 0 likes
  • 3 in conversation