BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aminkarimid
Lapis Lazuli | Level 10

Hello everybody;
I have two tables. One of them is in excel and the other one is in access. The excel file has name, date and volume1 variables. The access file has name, date and volume2 variables. I want to merge them by name & date. In other word, I want that SAS find the same date and name, and then merge volume1 & volume 2 variables. There is missing data in the excel file.

How can I do that?
Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Do you have issues with importing the two tables into SAS ?

What variable type are the dates in both tables? are they sas dates or sas datetime? or character type?

 

Suppose no - then sort the tables if need then just merge them:

proc sort data=table01; by date name; run;
proc sort data=table02; by date name; run;

data want;
 merge table01 table02;
   by date name;
run;

If you have more issues post your full log.
 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

I'd have to say it's not clear to me the point of your question.

 

This is a simple MERGE in SAS, do you have a more detailed problem description?

--
Paige Miller
aminkarimid
Lapis Lazuli | Level 10
How can I do that?
PaigeMiller
Diamond | Level 26

I am asking for a much more detailed statement of what you want to do AND what you are having a problem with.

--
Paige Miller
aminkarimid
Lapis Lazuli | Level 10

I have two tables.

Table01:

 

date name time volume1 intraday
24/03/2008 abc 10:00 100 .
24/03/2008 abc 10:00 120 .
24/03/2008 abc 10:00 100 320
24/03/2008 abc 11:00 200 .
24/03/2008 abc 11:00 250 450
24/03/2008 abc 12:30 110 .
24/03/2008 abc 12:30 120 230
24/03/2008 xyz 09:30 250 .
24/03/2008 xyz 09:30 240 .
24/03/2008 xyz 09:30 170 660
24/03/2008 xyz 10:00 180 .
24/03/2008 xyz 10:00 140 .
24/03/2008 xyz 10:00 110 430
24/03/2008 xyz 12:00 90 90
25/03/2008 abc 09:30 110 .
25/03/2008 abc 09:30 210 .
25/03/2008 abc 09:30 100 420
25/03/2008 abc 10:00 100 100
25/03/2008 abc 11:00 210 .
25/03/2008 abc 11:00 220 .
25/03/2008 abc 11:00 260 690
25/03/2008 asdf 11:00 150
25/03/2008 asdf 11:00 100 250
25/03/2008 asdf 12:30 110 .
25/03/2008 asdf 12:30 200 .
25/03/2008 asdf 12:30 260 570
25/03/2008 xyz 09:00 300 300
25/03/2008 xyz 09:30 250 .
25/03/2008 xyz 09:30 170 .
25/03/2008 xyz 09:30 170 590
25/03/2008 xyz 11:30 200 200

 

Table02:

 

date name Trade volume2
24-Mar-2008 abc 10 1000
24-Mar-2008 asd 20 1180
24-Mar-2008 xyz 15 1500
24-Mar-2008 qwe 30 2000
25-Mar-2008 zxc 10 900
25-Mar-2008 abc 15 1210
25-Mar-2008 xyz 25 1090
25-Mar-2008 fgh 15 1340
26-Mar-2008 abc 12 1250

 

I want to merge data such as below:

 

Table03:

 

date name time volume1 intraday volume2
24/03/2008 abc 10:00 100 . .
24/03/2008 abc 10:00 120 . .
24/03/2008 abc 10:00 100 320 .
24/03/2008 abc 11:00 200 . .
24/03/2008 abc 11:00 250 450 .
24/03/2008 abc 12:30 110 . .
24/03/2008 abc 12:30 120 230 1000
24/03/2008 xyz 09:30 250 . .
24/03/2008 xyz 09:30 240 . .
24/03/2008 xyz 09:30 170 660 .
24/03/2008 xyz 10:00 180 . .
24/03/2008 xyz 10:00 140 . .
24/03/2008 xyz 10:00 110 430 .
24/03/2008 xyz 12:00 90 90 1180
25/03/2008 abc 09:30 110 . .
25/03/2008 abc 09:30 210 . .
25/03/2008 abc 09:30 100 420 .
25/03/2008 abc 10:00 100 100 .
25/03/2008 abc 11:00 210 . .
25/03/2008 abc 11:00 220 . .
25/03/2008 abc 11:00 260 690 1210
25/03/2008 xyz 09:00 300 300 .
25/03/2008 xyz 09:30 250 . .
25/03/2008 xyz 09:30 170 . .
25/03/2008 xyz 09:30 170 590 .
25/03/2008 xyz 11:30 200 200 1090

 

How can I make the table03 by merging data?

 

Thank you

 

Shmuel
Garnet | Level 18

Do you have issues with importing the two tables into SAS ?

What variable type are the dates in both tables? are they sas dates or sas datetime? or character type?

 

Suppose no - then sort the tables if need then just merge them:

proc sort data=table01; by date name; run;
proc sort data=table02; by date name; run;

data want;
 merge table01 table02;
   by date name;
run;

If you have more issues post your full log.
 

Kurt_Bremser
Super User

These are not datasteps that read data from datalines, so we still have no idea what types the variables are and what formats are used.

The Excel file is also useless to convey that information.

PLEASE POST YOUR DATA AS DATASTEPS WITH DATALINES.

I hope that was clear enough now.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 7 replies
  • 840 views
  • 3 likes
  • 4 in conversation