Dear Forum,
i have one question for you all i am doing scoring for one nutrition data.
i have sample data like this
onoin potato cauli_filower vegetables
1 0 1
0 1 1
1 1 1
0 0 1
0 0 0
so i am going to creat new variable called vegetables suppose the respondent consumes onion and cauli flower the i need to enter 1
i need result like
1 1 1 =1
0 1 0 =1
0 0 0 =0
1 1 0 =1
so for this i need to use if and then condition in between the if and then i need to use 'and' also please give me some i dea wether it works or not??
thanks
Anil
Hi,
You could use nested if statements, however it could get quite messy e.g:
data want;
set have;
vegetables=0;
if onion=1 or potato=1 or calui_flower=1 then vegetables=1;
...
Maybe think of it slightly differently:
data want;
set have;
vegeables=0;
if sum(onion,potato,cauli_flower)>0 then vegetables=1;
run;
There are other functions also that could do a similar thing.
You don't even need to use an if, then statement.
data want;
set have;
vegetable = max(onion,potato,cauli_flower);
run;
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.
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.