BookmarkSubscribeRSS Feed
BIKI
Calcite | Level 5

I have a variable name food.

food has 8 value labels ranges from 1 to 8.

I want to create a variable called range by using the value level of food.

 

let us suppose I have the dataset name as diet.

 

 

data food1;
set work.diet;
if food <=2 then range=1;
else if 3<= food <=5 then range=2;
else if 6<= food <=7 then range=3;
else if 3<= food <=7  then range=4;
else if food>=8 then range=5;

run;

 

 

the problem line 6 else if 3<= food <=7 then range=4  is not accounting by sas 9.4 as the value is overlapping while creating range variable.

i want a variable with this overlapping code.

it is creating the value label of range 1 2 3 and 5.

it is not accounting the above-highlighted command.

can anyone help me with this?

 

 

1 REPLY 1
ghosh
Barite | Level 11

Create first a custom format using the multilabel option, for example

proc format library=work;
value foodf (multilabel notsorted)
low-2=1
3-5=2
6-7=3
3-7=4
8-high=5;
run;

Now how you would use it depends on the which PROC you will use it for.  For further details check out:

https://blogs.sas.com/content/sgf/2016/12/16/creating-and-using-multilabel-formats/

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 723 views
  • 3 likes
  • 2 in conversation