DATA Step, Macro, Functions and more

Where condition in Proc Means

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Where condition in Proc Means

 

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!


Accepted Solutions
Solution
‎05-24-2017 08:49 PM
Super User
Posts: 19,817

Re: Where condition in Proc Means

Posted in reply to Kalai2008

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


All Replies
Super User
Posts: 11,343

Re: Where condition in Proc Means

Posted in reply to Kalai2008

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.

Contributor
Posts: 70

Re: Where condition in Proc Means

Thank you ..It worked
Senior User
Posts: 1

Re: Where condition in Proc Means

Posted in reply to Kalai2008

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;

Contributor
Posts: 70

Re: Where condition in Proc Means

Posted in reply to shanmukh2
Thank you ..It worked..
I tried before like this...instead I used '%(H)%'
PROC Star
Posts: 1,760

Re: Where condition in Proc Means

Posted in reply to Kalai2008
proc  means data=Test.Country(where=(bbk_country contains '(H)' ));

Contributor
Posts: 70

Re: Where condition in Proc Means

Thank you..It worked
Solution
‎05-24-2017 08:49 PM
Super User
Posts: 19,817

Re: Where condition in Proc Means

Posted in reply to Kalai2008

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!


 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 205 views
  • 4 likes
  • 5 in conversation