BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6

Dear All

 

  I want to use proc format to group the continuous variables.  

  Here is the code

  Proc format;

  value Var_A  0 = Var_A le 10 'Less than 10' ;

   Value VAR_A 10 = Var_A le 20 ''Between 10 and 20'  /* and so on */;

   run;

 

What is the mistake I am making?

Thank you in advance.

  Randy

3 REPLIES 3
PaigeMiller
Diamond | Level 26
 Proc format;
    value var_A  0-<10='<10'
        10-<20 = '10-20' 20-<30='20-30' ... ;
run;
--
Paige Miller
Tom
Super User Tom
Super User

The format just needs to specify the value ranges, it has nothing to do with any particular variable until you try to use it with that variable.

Also you should include all of the ranges in one format definition.

proc format;
  value fmt_A 
       low - 10 = 'Less than 10' 
       10 - 20 = 'Between 10 and 20' 
       20 - high = 'More than 20'
  ;
run;

proc freq data=have;
  format var_a fmt_a.;
run;
ballardw
Super User

Proc format ranges use the -  character to indicate a range is specified and use the < (and ONLY the < character) to indicate whether the value is included in the range or not

1 - 10     values 1 through 10 are in the range

1 <- 10   values from 1 to 10 EXCLUDING 1 are in the range

1 - <10  values from 1 to 10 excluding 10 are in the range

1 <-< 10 values from 1 to 10 but excluding both 1 and 10 are in the range.

 

A couple of special values are also available Low for the smallest non-missing value, High for the largest non-missing value you system uses. These can be useful when you aren't sure of an exact value

 

low -<0   all values less than 0 excluding 0 (i.e. all negative numbers)

50 <- high  all values greater than 50

 

And another special value range is OTHER where anything not explicitly included in some range is dumped:

1 - 10 ="range 1"

15-25 = "range 2"

30-43= "range 3"

other = "everything else"  <= this would include missing unless you have specific assignment for missing

;

You can mix ranges and lists of values in the same format as well.

 

Unless you really understand character comparisons do not expect ranges to work with character variables in general. Ranges can be used in character formats but the results are often not as expected.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1228 views
  • 0 likes
  • 4 in conversation