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?
data newdata;
set original;
if find( ISIN,'HK','i')>0;
run;
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!
using substr:
if substr(your_variable,1,2) in ('HK','CN');
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!!
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.