Hello,
today I wanted to merge two data sets together to finally draw some plots with the data. I got the code working outside of a macro, but as I have more data sets I wanted to create a macro for this:
Lets say I have data like this:
data data1;
input y ;
datalines;
1
2
4
2
6
4
3
4
;
data data2;
input y ;
datalines;
4
3
7
5
6
9
5
4
;Now I want to merge the two data sets:
%MACRO createPlotData(data1 , data2);
proc sql;
create table plot1 as
select
y
from
&data1
;
quit;
proc sql;
create table plot2 as
select
y as y1
from
&data2
;
quit;
data outputPlotData;
set plot1 plot2;
run;
%MEND;The code is working when I use it outside of the macro. I already googeld and looked in this forum for a solution but I could not get the code to work. I think I need to at something inside the proc sql code?
Thanks for your help!
Your code is working for me:
data data1;
input y ;
datalines;
1
2
4
2
6
4
3
4
;
data data2;
input y ;
datalines;
4
3
7
5
6
9
5
4
;
%MACRO createPlotData(data1 , data2);
proc sql;
create table plot1 as
select
y
from
&data1
;
quit;
proc sql;
create table plot2 as
select
y as y1
from
&data2
;
quit;
data outputPlotData;
set plot1 plot2;
run;
%MEND;
%createPlotData(data1,data2)
Your code is working for me:
data data1;
input y ;
datalines;
1
2
4
2
6
4
3
4
;
data data2;
input y ;
datalines;
4
3
7
5
6
9
5
4
;
%MACRO createPlotData(data1 , data2);
proc sql;
create table plot1 as
select
y
from
&data1
;
quit;
proc sql;
create table plot2 as
select
y as y1
from
&data2
;
quit;
data outputPlotData;
set plot1 plot2;
run;
%MEND;
%createPlotData(data1,data2)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.