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

 

Hi All,

 

Thank you for looking into this.

Need a quick help. I am using Proc Means, where I need to filter only the variable that have countries listed in (H)..That is I need only afghanistan and china. There are more than 50 countries listed.

 

ex..Variable Name: bbk_country

      Algeria

      Afghanistan(H)

      China(H)

      US

      Nigeria

 

proc  means data=Test.Country(where=(bbk_country in ('(H)')));

class bbk_country;

var amount;

run;

 

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

IN in SAS is an operator and allows you to search for multiple values. You need to search your string and the appropriate functions for that are FIND/INDEX or LIKE. 

 

Example of IN

 

where country in ('Afghanistan', 'China');

Example of FIND

 

where find(country, '(H)')>0;

@Kalai2008 wrote:

 

Hi All,

 

Thank you for looking into this.

Need a quick help. I am using Proc Means, where I need to filter only the variable that have countries listed in (H)..That is I need only afghanistan and china. There are more than 50 countries listed.

 

ex..Variable Name: bbk_country

      Algeria

      Afghanistan(H)

      China(H)

      US

      Nigeria

 

proc  means data=Test.Country(where=(bbk_country in ('(H)')));

class bbk_country;

var amount;

run;

 

 

Thanks!


 

View solution in original post

7 REPLIES 7
ballardw
Super User

You may be more limited using the dataset option where than a separate where clause.

 

You can use functions in a WHERE statement such as:

proc means data=Test.Country ;

where find(bbk_country,'(H)','i')>0;

 

 

which would find (H) or (h) with the 'i' option.

Kalai2008
Pyrite | Level 9
Thank you ..It worked
shanmukh2
Fluorite | Level 6

You can try like this if you only want to filter countries that are listed with (H)

 

proc  means data=Test.Country(where=(bbk_country like '%(H)'));

class bbk_country;

var amount;

run;

Kalai2008
Pyrite | Level 9
Thank you ..It worked..
I tried before like this...instead I used '%(H)%'
ChrisNZ
Tourmaline | Level 20
proc  means data=Test.Country(where=(bbk_country contains '(H)' ));

Kalai2008
Pyrite | Level 9
Thank you..It worked
Reeza
Super User

IN in SAS is an operator and allows you to search for multiple values. You need to search your string and the appropriate functions for that are FIND/INDEX or LIKE. 

 

Example of IN

 

where country in ('Afghanistan', 'China');

Example of FIND

 

where find(country, '(H)')>0;

@Kalai2008 wrote:

 

Hi All,

 

Thank you for looking into this.

Need a quick help. I am using Proc Means, where I need to filter only the variable that have countries listed in (H)..That is I need only afghanistan and china. There are more than 50 countries listed.

 

ex..Variable Name: bbk_country

      Algeria

      Afghanistan(H)

      China(H)

      US

      Nigeria

 

proc  means data=Test.Country(where=(bbk_country in ('(H)')));

class bbk_country;

var amount;

run;

 

 

Thanks!


 

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
  • 7 replies
  • 26309 views
  • 4 likes
  • 5 in conversation