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/