Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Management / merging question

Status
Not open for further replies.

Medvedeff

Instructor
Feb 12, 2008
29
US
Ive have encountered a problem that I just cannot seem to solve...

I have a two datasets, one with 10 observations and one with 5 observations. The one with 5 observations contains a variable of unique integers bounded on the interval [1,10]. I want to merge the two datasets in a way that the value of each integer will match with the corresponding observation number. For example, consider the values 2 4 6 8 10. I want the two datasets merged in a way that the resulting dataset will contain the integers in the following way:

OBS Integer
1 .
2 2
3 .
4 4
5 .
6 6
7 .
8 8
9 .
10 10

Does anybody have any suggestions? I am very appreciative of any help that you can provide me.
 
Yup, use the _n_ variable to append the record number to the dataset as a variable you can use, then use a regular merge to join them together.
Code:
dset10b;
  set dset10;

  integer = _n_;
run;

data joined;
  merge dset10b
        dset5;
  by integer;
run;

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thank you! I was so concerned with preserving the original order of the 10 observation dataset that I didnt even think about doing it as you suggested. Thanks again.
 
No worries. Any time you're worried about retaining the order of a file, just append a recno field at the start, then you'll be home free. :)

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top