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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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)

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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)

mrer
Fluorite | Level 6
True! **bleep** it... got confues by result pages which comes up automatically after running the code. It showed a different data set. thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 848 views
  • 0 likes
  • 2 in conversation