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
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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