SAS : Power of PROC FORMAT

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 20% off till July 14, 2017

This tutorial explains the uses of PROC FORMAT in the most common data manipulation tasks.

Sample Data

Data Source : sashelp.cars
Sample Data
Example 1 :
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 :
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'
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;
data temp;
set sashelp.cars;
TSRP = put(msrp, range.);run;
Example 3 : Subset Data

Method 1 : 
data temp;
set sashelp.cars;
where put(msrp, range.) IN ('High' 'Medium');
run;
Method 2 : 
data temp (where = (tsrp IN ('High' 'Medium')));
set sashelp.cars;
tsrp = put(msrp, range.);
run;
Method 3 :
proc sql;
select *,
put(msrp, range.) as tsrp
from sashelp.cars
where calculated tsrp in ('High', 'Medium');
quit; 

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

0 Response to "SAS : Power of PROC FORMAT"

Post a Comment

Next → ← Prev