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
I get this message in Log
remove semicolon after male
VALUE gender 1 = 'Male';
2 = 'Female';
check for case sensitivity of format vs value
VALUE $color 'y' = 'Yellow'
'G' = 'Green'
'B' = 'Blue'
'W' = 'White';
lol happens to me too. Just a syntax issue. Have fun!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.