BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,.

I use the code to merge the two files , the code is -

Data One;
INFILE "C:\sas\data_A.dat";
INPUT Time $1-8
Date $9-18
Model $19-24
Unit 25-27
INT 28;
RUN;


proc print data = Data One;
run;

Data Two;
INFILE "C:\sas\data_B.dat";
INPUT Time $1-8
Note $9-16;
RUN;

PROC PRINT DATA = Two;
RUN;

/*Concatenate data One and Two*/
data CONCAT;
SET One and Two;
RUN;

/*Sort One and Two by Time*/
PROC SORT DATA = CONCAT OUT = CAT_SORT;
BY Time;
RUN;

Proc Print Data = CAT_SORT;
RUN;


Thius works well and the files get merged , the problem is that each row is repeated twice with the variables from the first file in the first line and the variable "Note" in the second line with the same variable "Time". So, if I need to export this in Excel then i get ,say, 400 rows when actually the count should be 200. Is there a way that the varible "Note" from second data is printed in the same line as are the other 5 variables from the first data ?

Kindest Regards,
Mark
3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12
I'm surprised that you didn't get an error from this step:

/*Concatenate data One and Two*/
data CONCAT;
SET One and Two;
RUN;

"and" is treated as a separate dataset.

Your PROC PRINT's also have incorrect syntax.

The SET statement concatenates the two datasets. Concatenate means to "stack" vertically. If you want to string out two datasets to make longer rows, then you need the MERGE statement. Probably something like this will work:

PROC SORT DATA=one; BY time; RUN;
PROC SORT DATA=two, BY time; RUN;

*Merge data One and Two;
data CONCAT;
MERGE One Two;
BY time;
RUN;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
There are three key concepts here: merge, concatenate and interleave, for your consideration, depending on the output requirements, and also, as much, your input data and considering compatability (again, information given up in the SAS log).

Recommended SAS support website - Google advanced search argument below this topic / post:

data step programming merge concatenate site:sas.com

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Cynthia_sas
Diamond | Level 26
Hi:
In addition to Doc and Scott's suggestions, these previous forum postings both have concrete examples of concatenating versus merging SAS datasets:
http://support.sas.com/forums/thread.jspa?messageID=19272䭈
http://support.sas.com/forums/thread.jspa?messageID=2613ਵ

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1427 views
  • 0 likes
  • 4 in conversation