Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Merging Datasets with unequal observations and no common variable

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-11-2019 01:15 PM
(825 views)

Hi,

I am struggling to combine datasets with unequal observations in SAS and no common variables between them.

Example: I have a dataset A and Dataset B and will be needing data set c which should look something like follows. Is there any I could do this? When there are no common variables in dataset A and B and not having equal observations in those datasets.

Data set A: Dataset B Dataset C

ID NAME CODE begin end ID Name Code begin end

1 X 123 120 130 1 x 123 120 30

2 Y 125 500 600 2 y 125 500 600

3 Z 567 3 z 567 120 30

4 A 783 4 A 783 500 600

Thanks very much!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks so much for your response. It works but can you please help me understand this

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You just want to repeat the records until the end?

Data set C is what you need exactly?

Does this need to expand to more records in Data set B or will you have only 2 records?

Data set C is what you need exactly?

Does this need to expand to more records in Data set B or will you have only 2 records?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Not really any type of merge. Looks like you want to cycle through the observations in B.

```
data want;
set a;
p=1+mod(_n_-1,nobs);
set b point=p nobs=nobs;
run;
```

What happens if A has fewer observations than B? What do want to do then? Would you want to do the same type of cycle through A?

```
data want;
if _n_ > max(nobs1,nobs2) then stop;
p1=1+mod(_n_-1,nobs1);
p2=1+mod(_n_-1,nobs2);
set a point=p1 nobs=nobs1;
set b point=p2 nobs=nobs2;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks so much for your response. It works but can you please help me understand this

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Mark the correct answer as the Solution please, not your own comment.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Sir!

I really appreciate your help with the previous question. I've got another problem and would like to use the help and advice of the SAS experts here.

I have multiple CSV data files with the same set of variables in every raw data file (also all the files are present in the same directory). I would like to import all of them once and create a new SAS.

Thanks for all your help in Advance!

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. **

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.