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

Hi,

 

I'm very new in SAS and I have problem which is difficult to me to settle.

 

I have two datasets.

 

First is:

nameage
cole12
emma13
lisa15

 

Second is:

answer
lisa_my_name

what??

 

How can I merge them by macro only for cases in which answer has values of name variable. The results should be:

answerage
lisa_my_name15

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @aaaaa34  All you need is a simple inner join or in other words a match merge

 

proc sql;
create table want as
select a.*,b.*
from second a inner join first b
on answer=name;
quit;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @aaaaa34  All you need is a simple inner join or in other words a match merge

 

proc sql;
create table want as
select a.*,b.*
from second a inner join first b
on answer=name;
quit;
aaaaa34
Calcite | Level 5
Hi thanks a lot. But I wonder if it's possible to put find condition into do until loop and the make join procedure?
%macro xxx(data_out=);
%let namelist=;
proc sql noprint;
select name
into :namelist separated by "!"
from bbb
;
run;
quit;

data &data_out;
set &data_out;
%let i_1 =1;
%do %until (%qscan(&namelist,&i_1,'!') = %str());
%let zm1=%scan(&namelist,&i_1,'!');
if find(namelist, "&zm1", "i")>0 then answer= answer;
%let i_1=%eval(&i_1+1);
%end;
run;
aaaaa34
Calcite | Level 5

I edited my post to show you more complex cases.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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