I'm trying to create a variable 'Baby' which contains either 'baby' or 'infant' or 'toddler' from a variable 'Brand'. I figured it out (after a long time, SAS novice here) how to do a single word (baby) but I would like to add two more (infant and toddler). Can you please help?? thank you 🙂
---here is my code---
Data baby ;
Set baby;
if find (Brand, "baby" , "i") then Baby = 1; else baby = 0; run;
if find (Brand, "baby" , "i")>0 or find(Brand,'infant','i')>0 or find(Brand,'toddler','i')>0 then Baby = 1; else baby = 0;
@Lena_PA wrote:
I'm trying to create a variable 'Baby' which contains either 'baby' or 'infant' or 'toddler' from a variable 'Brand'. I figured it out (after a long time, SAS novice here) how to do a single word (baby) but I would like to add two more (infant and toddler). Can you please help?? thank you 🙂
---here is my code---
Data baby ;
Set baby;
if find (Brand, "baby" , "i") then Baby = 1; else baby = 0; run;
You say you want a variable which contains 'baby' or 'infant' or 'toddler', but then you show code that assigns 0 or 1 to this variable. Please clarify what you want.
Oh sorry. I want to create a new variable name "BABY" = 1 if the existing variable "Brand" contains "baby" or "infant" or "toddler". If Brand does not include any of these three words, then BABY =0.
if find (Brand, "baby" , "i")>0 or find(Brand,'infant','i')>0 or find(Brand,'toddler','i')>0 then Baby = 1; else baby = 0;
Thank you so much!!!!!!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.