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

hi, im a new user and i m not sure how to keep the variables if the contain...

for example i have ISIN: HK0000077468. i want to keep the observations if  ISIN contains HK.

could you kindly provide ur guidance?

1 ACCEPTED SOLUTION

Accepted Solutions
JVarghese
Obsidian | Level 7

data newdata;

set original;

if find( ISIN,'HK','i')>0;

run;

View solution in original post

6 REPLIES 6
JVarghese
Obsidian | Level 7

data newdata;

set original;

if find( ISIN,'HK','i')>0;

run;

aarony
Obsidian | Level 7

thanks for ur kind reply. 2 additional question:

1) how would u write the code just to parse the 1st 2 characters? what does 'i' mean?

2) how can write the code if i want to do HK and CN?

ie)

data newdata;

set original;

if find( ISIN,'HK','i')>0 & find(ISIN, 'CN', 'i')>0;

run;

is not working....

thank you!

Linlin
Lapis Lazuli | Level 10

using substr:

if substr(your_variable,1,2) in ('HK','CN');

aarony
Obsidian | Level 7

Thank you so much! this is very helpful.

just one more qucik question if u dont mind:

*if i do them seperately, keep the ones with HK/CN;

data sortedbase4;

set sortedbase2;

if countrycode NE 'CN' then delete;

run;

data sortedbase4;

set sortedbase2;

if countrycode NE 'HK' then delete;

run;

and then try to append them....by

data sortbase3;

  update sortedbase3 sortbase4;

  by countrycode;

run;

i get an error. could u shed some light? thank you!!

Tom
Super User Tom
Super User

You have a typo in your dataset names such that you are created SORTEDBASE4 twice and not creating SORTEDBASE3.

You want to use a SET statement instead of an UPDATE.  UPDATE is used to apply transactions to a master dataset.

JVarghese
Obsidian | Level 7

if find( ISIN,'HK','i')>0 & find(ISIN, 'CN', 'i')>0;


Replace & with OR in your code, you'll get it right!


'i' is optional and it means to ignore the case of the string. Means whether HK or CN is in lower or upper case, that'll work irrespective of the case.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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