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!!!!!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.