This tutorial explains the uses of PROC FORMAT in the most common data manipulation tasks.
Sample Data
Data Source : sashelp.cars
Example 1 :
Sample Data
Data Source : sashelp.cars
![]() |
Sample Data |
Suppose you are asked to group MSRP variable based on the following conditions and check the number of observations falling in each groups
Values greater than 40,000 should be labelled 'High'
Values between 26,000 and 40,000 should be labelled 'Medium'
Else 'Low';
Solution
proc format;
value range
40000-high='High'
26000-< 40000='Medium'
other ='Low';
run;
proc freq data = sashelp.cars;
table msrp;
format msrp range.;
run;
Example 2 :
Method 1 :
Same as with example 1. But you are asked to create a new variable called TSRP based on the following conditions applied in MSRP variable.
Values greater than 40,000 should be labelled 'High'Solution :
Values between 26,000 and 40,000 should be labelled 'Medium'
Else 'Low'
proc format;
value range
40000-high='High'
26000-< 40000='Medium'
other ='Low';
run;
data temp;
set sashelp.cars;
TSRP = put(msrp, range.);run;
Example 3 : Subset Data
Method 1 :
data temp;Method 2 :
set sashelp.cars;
where put(msrp, range.) IN ('High' 'Medium');
run;
data temp (where = (tsrp IN ('High' 'Medium')));Method 3 :
set sashelp.cars;
tsrp = put(msrp, range.);
run;
proc sql;
select *,
put(msrp, range.) as tsrp
from sashelp.cars
where calculated tsrp in ('High', 'Medium');
quit;
How to sum saary department wise using proc format
ReplyDeleteSalary*
DeleteHow do you make a format library auto-start for each new SAS session?
ReplyDelete