BookmarkSubscribeRSS Feed
imanojkumar1
Quartz | Level 8

I have the following table_1 :

 

TPMCPWCPWSCSiteETDateTimeDIAMPXMCSF
71017101US0005211Lathing08Nov201611:58890.3 1
71027102US0003611Lathing02Nov201613:01878.1 1
71027102UC0003482Lathing07Nov201618:22877.3 1
71067106UC004241Lathing05Oct20169:43890,4 1
71067106UC004373Lathing07Nov201618:23877.1 1
71067106UC3094Lathing07Nov201618:26877.8 1
71077107UC053271Lathing06Oct20168:41837 1
71077107UC2002Lathing13Oct201612:53890.55 1
71087108UC0003613Lathing02Nov201613:01878.1 1
71087108UC004321Lathing07Nov201618:25877.8 1
71087108UC1062Lathing03Oct20169:37890.3 1

 

 

 

and table_2 :

 

TPMCPWCPWSCSiteETDateTimeDIAMPXMCSF
7101....01JAN16....
7101....02JAN16....
..........
..........
..........
7101....30DEC16....
7101....31DEC16....
7102....01JAN16....
7102....02JAN16....
..........
..........
..........
7102....30DEC16....
7102....31DEC16....

 

 

 

I want to merge two tables in a way that the output should look like something:

TPMCPWCPWSCSiteETDateTimeDIAMPXMCSF
7101....01JAN16....
7101....02JAN16....
..........
71017101US0005211Lathing08Nov201611:58890.3 1
..........
..........
7101....30DEC16....
7101....31DEC16....
7102....01JAN16....
7102....02JAN16....
..........
71027102US0003611Lathing02Nov201613:01878.1 1
71027102UC0003482Lathing07Nov201618:22877.3 1
..........
..........
7102....30DEC16....
7102....31DEC16....

 

 

How can it be done using 'Proc SQL' or 'Data Merge' or 'Combine'?

 

I want to learn all three methods for future use.

 

 

7 REPLIES 7
imanojkumar1
Quartz | Level 8

In the simplest form I used:

 

data data_set;
	set table_1 table_2;
run;

But this produced duplicate values of dates. For example:

 

 

TPMCPWCETPWSCSiteDateTimeDIAMPXMCSF
7618...129SEP2016 ...
7618..UC00424230SEP2016 ...
7618.LathingUC00437130SEP201617:15890.500000..
7618.LathingUC309230SEP201620:32890.500000..
7618...301OCT2016 ...
7618...102OCT2016 ...

 

 

 

I don't know how can I avoid this. I do not want rows where there is no 'ET' (i.e. ET is '.' or empty, I do not want those rows).

 

So in the final table there will not be the line which is 'BOLD' in above output sample. And similarly, all other 'such rows', in final output table, will not be there as well.

Ksharp
Super User
So ET is always missing in Table2?

data data_set;
	set table_1 table_2;
       by TPMC Date;
      if first.Date;
run;


imanojkumar1
Quartz | Level 8

Thanks for helping.

Yes second table has only missing data. but may be later in future table 2 might have data. as of now, it is missing only.

imanojkumar1
Quartz | Level 8

This will return only a table which is similar like table1. all of table2 rows are not added.

Kurt_Bremser
Super User

@imanojkumar1 wrote:

This will return only a table which is similar like table1. all of table2 rows are not added.


If ET is always missing in table2, then this is clearly a consequence of your requirement, quote:

"I do not want rows where there is no 'ET' (i.e. ET is '.' or empty, I do not want those rows)."

 

You might want to review your requirements and post a clear and concise rule which observations from the concatenation of the datasets you want.

And if you do not want to concatenate the datasets, but merge observations, then we need another method altogether.

 

Please post a sample of your input datasets and the wanted dataset, as it results from these example datasets.

Your initial example has data in the "want" dataset that is not present in the "have" datasets.

imanojkumar1
Quartz | Level 8

it is returning a table with headers only. no data.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 7 replies
  • 2146 views
  • 2 likes
  • 3 in conversation