BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

I need to create a flag where in one dataset i have few terms like andy, parci, mubdi and if in the other dataset i have these terms it should be flagged as Y. How can i merge them?

3 REPLIES 3
ballardw
Super User

Show some example data and what the files should look like after merging. Also if there are duplicates of the values involved in either data set then include an example so we can tell what need's to be done.

 

HB
Barite | Level 11 HB
Barite | Level 11

Here is one way guessing on the info we have:

 

data check_file;
   input data1 data2 checkterm $8.;
datalines;
1 2 andi
2 2 parka
3 3 whoopi
3 4 parci
6 5 mubdi
8 4 mudbi
9 1 parci
3 2 andy
5 3 andi
;
run;


data reference_file;
   input referenceterm $8.;
datalines;
parci
mubdi
andy
;
run;


proc sql;
	create table flagged_check_file as
	select data1, data2, checkterm,
	case when checkterm in (select referenceterm from reference_file) then 1 else 0 end as term_flagged
	from check_file;
quit;


proc print noobs;
run;

 

Which gives us:

                                                                    term_
                                    data1    data2    checkterm    flagged

                                      1        2       andi           0
                                      2        2       parka          0
                                      3        3       whoopi         0
                                      3        4       parci          1
                                      6        5       mubdi          1
                                      8        4       mudbi          0
                                      9        1       parci          1
                                      3        2       andy           1
                                      5        3       andi           0

But i agree with ballardw, post more info.

 

 

ShiroAmada
Lapis Lazuli | Level 10
data WANT;
input YOUR_TERMS: $1.;
cards;
A
B
C
D
E
;
run;

data WISH;
set WANT(obs=3);
run;

proc sql;
alter table WANT
add WHAT_U_WANT CHAR (1);

update WANT
set WHAT_U_WANT='Y'
where YOUR_TERMS in (select YOUR_TERMS from WISH);
quit;

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