Hi,
dataAB which is a vertical merge of data A and data B contains ID numbers 501-510 for data A and 501-510 for data B. Now i need to do a horizontal merge by ID of dataAB with baselinedata and it will not work. I believe i need to renumber my ID. How do I do that?
Data A ID: 501 502 503 504 505 506 507 508 509 510
Data B ID: 501 502 503 504 505 506 507 508 509 510
Baseline: 501 502 503 504 505 506 507 508 509 510 601 602 603 604 605
Code: *************Vertical Merge***********;
Data dataAB; set dataa datab;
run;
**************Horizontal Merge********;
data HorMerge2; merge dataAB baseline;
by ID;
Thanks.
@marianthi86 wrote:
Now i need to do a horizontal merge by ID of dataAB with baselinedata and it will not work.
Why doesn't it work? What happens? What is the error? Please tell us.
Since dataAB isn't in id order, you have to sort it before merging. e.g.:
data dataa; input ID @@; cards; 501 502 503 504 505 506 507 508 509 510 ; Data datab; input ID @@; cards; 501 502 503 504 505 506 507 508 509 510 ; data baseline; input ID @@; cards; 501 502 503 504 505 506 507 508 509 510 601 602 603 604 605 ; /* Code: *************Vertical Merge***********; */ data dataAB; set dataa datab; run; /* **************Horizontal Merge********; */ proc sort data=dataAB; by ID; run; data HorMerge2; merge dataAB baseline; by ID; run;
Art, CEO, AnalystFinder.com
You can't use SAS code to modify or change a data set that is opened in ViewTable. Close the ViewTable window first.
If you're using Enterprise Guide, particularly an older version of Enterprise Guide, just re-run the code. The error you received is explained in the following note: http://support.sas.com/kb/38/344.html
Art, CEO, AnalystFinder.com
Sorting, in itself, doesn't delete data. You never mentioned other columns. In order for anyone to help you'd have to show us your data and the code you ran.
My initial guess is that you had created data files that contained your actual data, but overwrote them with the datasets created by the code I posted.
Art, CEO, AnalystFinder.com
I didn't see any attachments. Regardless, to sort, simply use proc sort. You only have to sort what you called the vertical merge data and, if your baseline data isn't in ID order, you'd have to sort that as well before doing the horizontal merge.
Art, CEO, AnalystFinder.com
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 25. Read more here about why you should contribute and what is in it for you!
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.