DATA Step, Macro, Functions and more

custom formats 'partially' work

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

custom formats 'partially' work

19 1 14000 Y
45 1 65000 G
72 2 35000 B
31 1 44000 Y
58 2 83000 W

 

That's my data for 'car customers' and each field representing age, sex, income, and preferred color.

 

Below is my code:

 

DATA cars;
	INFILE '/folders/myfolders/sasuser.v94/universecars.txt';
	INPUT Age Gen Income CarColor $;
RUN;

PROC FORMAT;
	VALUE agegroup	13 -< 20 = 'Teen'
					20 -< 65 = 'Adults'
					65 - high = 'Senior';
	VALUE gender	1 = 'Male';
					2 = 'Female';
	VALUE incrange	0 -< 20000 = 'Extreme Low'
					20000 -< 40000 = 'Low'
					40000 -< 60000 = 'Med'
					60000 -< 80000 = 'High'
					80000 - HIGH = 'Extreme High';
	VALUE $color	'y' = 'Yellow'
					'G' = 'Green'
					'B' = 'Blue'
					'W' = 'White';
					
PROC PRINT data=cars;
	FORMAT Age agegroup. Gen gender. Income incrange. CarColor $color.;
RUN;

 

 

and the results when I run, does not interprete number 2 in 'sex' field as 'female'.

Strange enough, 1 works as a 'male'. and it doesnot work for Y, neither.

 

Obs

Age

Gen

Income

CarColor

1

Teen

Male

Extreme Low

Y

2

Adults

Male

High

Green

3

Senior

2

Low

Blue

4

Adults

Male

Med

Y

5

Adults

2

Extreme High

White

 

 

Please help


Accepted Solutions
Solution
3 weeks ago
PROC Star
Posts: 1,792

Re: custom formats 'partially' work

Posted in reply to jimmychoi

remove semicolon  after male

 

VALUE gender	1 = 'Male';
					2 = 'Female';

 

View solution in original post


All Replies
Occasional Contributor
Posts: 6

Re: custom formats 'partially' work

Posted in reply to jimmychoi

I get this message in Log

83 ! 2 = 'Female';
_
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
Solution
3 weeks ago
PROC Star
Posts: 1,792

Re: custom formats 'partially' work

Posted in reply to jimmychoi

remove semicolon  after male

 

VALUE gender	1 = 'Male';
					2 = 'Female';

 

PROC Star
Posts: 1,792

Re: custom formats 'partially' work

Posted in reply to novinosrin

check for case sensitivity of format vs value

 

	VALUE $color	'y' = 'Yellow'
					'G' = 'Green'
					'B' = 'Blue'
					'W' = 'White';

  

Occasional Contributor
Posts: 6

Re: custom formats 'partially' work

Posted in reply to novinosrin
Works like a charm thank you so much
Why didn't I find that???
and thanks again for the comments for the case sensitivity of formats, I will work on that
PROC Star
Posts: 1,792

Re: custom formats 'partially' work

Posted in reply to jimmychoi

lol happens to me too. Just a syntax issue. Have fun!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 87 views
  • 0 likes
  • 2 in conversation