Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

format - Categorizing variabels in SAS using a range system

I have the numeric values of salaries of different employee's. I want to break the ranges up into categories. However I do not want a new column rather, I want to just format the existing salary column into this range method:

At least $20,000 but less than $100,000 -

At least $100,000 and up to $500,000 - >$100,000

Missing - Missing salary

Any other value - Invalid salary

I've done something similar with gender. I just want to use the proc print and format command to show salary and gender.

DATA Work.nonsales2;
SET Work.nonsales;
RUN;

PROC FORMAT; 
VALUE $Gender 
'M'='Male' 
'F'='Female' 
'O'='Other'  
other='Invalid Code';

PROC FORMAT; 
VALUE salrange 
'At least $20,000 but less than $100,000    '=<$100,000 
 other='Invalid Code';


PROC PRINT;
title 'Salary and Gender';
title2 'for Non-Sales Employees';
format gender $gender.;
RUN;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Proc Format is the correct method and you need a numeric format:

 proc format;
 value salfmt
 20000 - <100000 = "At least $20,000 but less than $100,000"
 100000 - 500000 = "100,000 +"
 . = 'Missing'
 other = 'Other';

Then in your print apply the format, similar to what you did for gender.

format salary salfmt.;

This should help get you started.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...