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

Dear experts,

 

assuming the following data set "have":

data have0;
country="BU"; output;
country="JP"; output;
country="US"; output;
run;
data have1;
value_list="US_ UK _JP NW"; output;
value_list="US_ UK _JP NW"; output;
value_list="US_ UK _JP NW"; output;
run;
data have; merge have0 have1 ;run;

 

I would like to obtain the following one:

 

data want
country="BU"; output;
run;

 

which is the most short, understandable and elegant way? 

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Please try this.

 

data want(keep=country);
set have;
if not find(strip(value_list),strip(country));
run;

View solution in original post

2 REPLIES 2
stat_sas
Ammonite | Level 13

Please try this.

 

data want(keep=country);
set have;
if not find(strip(value_list),strip(country));
run;

rogerjdeangelis
Barite | Level 11
HAVE

data have0;
country="BU"; output;
country="JP"; output;
country="US"; output;
run;

/*
Up to 40 obs WORK.HAVE0 total obs=3

Obs    COUNTRY

 1       BU
 2       JP
 3       US
*/


data have1;
value_list="US_ UK _JP NW"; output;
value_list="US_ UK _JP NW"; output;
value_list="US_ UK _JP NW"; output;
run;

/*
Up to 40 obs WORK.HAVE1 total obs=3

Obs     VALUE_LIST

 1     US_ UK _JP NW
 2     US_ UK _JP NW
 3     US_ UK _JP NW
*/


WANT

Up to 40 obs WORK.WANT total obs=1

Obs    COUNTRY

 1       BU


SOLUTION

* if the list does not change;
data mrg;
     merge have0 have1;
     if index(valuelist,country)=0 then output;
run;quit;


Up to 40 obs WORK.MRG total obs=1

Obs    COUNTRY     VALUELIST

 1       BU       US UK JP NW


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
  • 732 views
  • 0 likes
  • 3 in conversation