BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tritringuyen
Quartz | Level 8

Hello,

 

I want to combine two datasets (file attached). In general, the objective is to copy a specific string of texts in one dataset for all observations in another dataset.

 

Thank you very much!

 

Thierry

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

In general, a solution would be:

 

proc sql;

create table a3 as select * from a1, a2;

quit;

 

There are other simple ways, if you know that your data set a2 always contains a single observation.  For example:

 

data a3;

if _n_=1 then set a2;

set a1;

run;

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data, in the form of a datastep in the body of the post.  I am not opening some dodgy internet xl file.  If you need to combine datasets then this is called merging (SAS) or joining (SQL).  In each instance you identify common identifiers in both datasets, then merge one to the other based on collection of observations you want at the end, this graphic shows the types of SQL joins (merge has similar):

Capture.PNG

tritringuyen
Quartz | Level 8

I need a code because I have thousands opairs of datasets which I need to combine one with its partner. Thank you very much!

 

Thierry

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then you need to hire a contractor, this is a question and answer board - you asked how to join data from one dataset to another you do that by joins or by merges as described in that graphic which also provides code on how to do such a thing.  Once you have one working then you can look at creating a macro - depends on how samey your data is.  

Astounding
PROC Star

In general, a solution would be:

 

proc sql;

create table a3 as select * from a1, a2;

quit;

 

There are other simple ways, if you know that your data set a2 always contains a single observation.  For example:

 

data a3;

if _n_=1 then set a2;

set a1;

run;

tritringuyen
Quartz | Level 8

Dear @Astounding Thank you very much for your code. It is simple but it is all I need. The code is very helpful for me. Thanks.

 

Thierry

Kurt_Bremser
Super User

The proper way to supply example data is a data step with datalines included. While Excel files can easily carry malware and are therefore blocked by most company firewalls, SAS code is just text and considered harmless.

It is also a matter of basic courtesy, as it enables your potential helpers to recreate your data with a simple copy/paste and run.

tritringuyen
Quartz | Level 8
Thank you very much, in the future I will take into account this matter.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1783 views
  • 5 likes
  • 4 in conversation