BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
singhsahab
Lapis Lazuli | Level 10

Hi All,

 

I've two datasets , called test1 and test2 , i want to create one more dataset based upon "name" fields with all the data of test1 and test2. I want to add one more field like "action_flag"  with value 1 or 0. if name match then action_flag=1 else 0

 

data test1;
input id name $;
cards;
1 ab
2 cf
3 er
;
run;
data test2;
input id name $;
cards;
1 ab
2 df
3 er
4 hj
;
run;

 

Thank you in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sort data=test1;
  by name;
run;
proc sort data=test2;
  by name;
run;
data want;
  merge test1 (in=a) test2 (in=b);
  by name;
  action_flag=ifn(a and b,1,0);
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sort data=test1;
  by name;
run;
proc sort data=test2;
  by name;
run;
data want;
  merge test1 (in=a) test2 (in=b);
  by name;
  action_flag=ifn(a and b,1,0);
run;
Astounding
PROC Star

I'm interpreting the problem slightly differently:

 

proc sort data=test1;

by id;

run;

proc sort data=test2;

by id;

run;

data want;

merge test1 (rename=(name=name1))

test2 (rename=(name=name2));

by id;

action_flag = (name1=name2);

run;

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
  • 3380 views
  • 1 like
  • 3 in conversation