DATA Step, Macro, Functions and more

Use formatted value in where statement

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Use formatted value in where statement

I would like to use formats to group values and then select one of the formed groups with a where statement.

Consider the following simple code:

proc format;
      value enginesSML
            low-2 = 'Small'
            2-3 = 'Medium'
            3-high = 'Large';
run;

data tmp;
      format engines enginesSML.;
      set sashelp.cars(keep=engineSize);
      engines = engineSize;
run;


proc print data=tmp(obs=5);
      *where engines='Large'; /*Does not work*/
       where engines > 3; /*works*/
run;

How can I get this statement to work?

where engines='Large';

 

I'm on SAS 9.2.


Accepted Solutions
Solution
‎09-11-2017 12:10 PM
Super User
Posts: 10,283

Re: Use formatted value in where statement

Use this:

where put(engines,enginesSML.) = 'Large';
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎09-11-2017 12:10 PM
Super User
Posts: 10,283

Re: Use formatted value in where statement

Use this:

where put(engines,enginesSML.) = 'Large';
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 69 views
  • 0 likes
  • 2 in conversation