DATA Step, Macro, Functions and more

Data step combining data

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

Data step combining data

I have a basic question:

data test; set temp1 temp2;run;

Temp1 and temp2 are 2 datasets with similar columns. Can somebody explain what this command is doing. Is it a union of the two datasets. Is there a better proc sql alternative to combine temp1 and temp2. 

Thanks


Accepted Solutions
Solution
‎12-31-2017 09:04 AM
Super User
Posts: 9,880

Re: Data step combining data

Posted in reply to Agent1592

This is like a union all in sql. But compare your data step code with the necessary sql code:

proc sql;
create table test as
select * from temp1
union all
select * from temp2;
quit;

and you'll see why it's rarely used when the data step is much more concise. Aside from the fact that the data step has capabilities beyond those of sql.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 5,849

Re: Data step combining data

Posted in reply to Agent1592
Yes it is like a union.
Better depends in your requirements/preferences, but doing it in SQL would get you similar results.
Data never sleeps
Solution
‎12-31-2017 09:04 AM
Super User
Posts: 9,880

Re: Data step combining data

Posted in reply to Agent1592

This is like a union all in sql. But compare your data step code with the necessary sql code:

proc sql;
create table test as
select * from temp1
union all
select * from temp2;
quit;

and you'll see why it's rarely used when the data step is much more concise. Aside from the fact that the data step has capabilities beyond those of sql.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 197 views
  • 2 likes
  • 3 in conversation