This type of recoding:
if RIGHT_HOURS = .M or RIGHT_HOURS = ' ' then New_Time = 'Missing';
if '0.0000'<=RIGHT_HOURS <'2.0000' then New_Time = 'LT2' ;
if '2.0000'<=RIGHT_HOURS then New_Time = '> 2+';
IF right_hours is numeric (the .M as a special missing makes be believe that it is) often is not needed.
When you want to process groups of values of a variable then a custom format is often preferable as it doesn't need to modify any data set, which may take time, and can be quite flexible by having multiple formats or modifying the format definition.
An example you might be able to run:
proc format;
value right_hours
0 -< 2 = 'LT2'
2 - high = '>2+'
.,.M = 'Missing'
;
run;
proc freq data=name2;
table right_hours /missing;
format right_hours right_hours. ;
run;
If your name2 data set has trillions of records then the data storage space and time to run to create the data set name3 could be prohibitive. Custom formats like this will be honored by analysis and reporting procedures for just about any grouping purpose and usually for graphing as well with some caveats.
Advantages to formats include:
typically easier coding than multiple If/then/else statements
easier to understand once familiar
ease of modification
with numeric values the formatted values will appear in value order
reduces the number of needed variables when one is based solely on another single variable
one format can be applied to multiple variables that need the same rules
lists of specific values may be much easier to code
and for advanced purposes a lookup data set may be used to create the formats
Consider a data set with person ages. I used to have to report on 5-year based age groups, 10-year based age groups, ages like 18 to 25, 26 to 40, 41 to 65 and 65+ (and a few other groups based on specific projects). I did not need a specific variable for each but had separate formats used with which ever age variable was appropriate for the data set such as age at marriage, treatment, enrollment or departure from program.
... View more