BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
joachimg
Obsidian | Level 7

I'm creating a new variable, d_religion2 from an existing variable, d_religion. All I'm trying to do is redefine the categories of the variable (should be super easy, right?). In the dataset I'm working with, the categories of d_religion are words - catholic, evangelical, jewish, etc. - I attached a screen shot of a table of d_religion so you can see what I mean. How do I write that in an if/then statement? Because writing something like "if d_religion=catholic then d_religion2=christian;" for example, doesn't work. Hopefully this is clear......let me know if you have questions. I know this is probably simple haha. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Since I never download attachments, I'll take a guess here

 

data want;
    set have;
    if upcase(d_religion)='CATHOLIC' then d_religion2='CHRISTIAN';
    else if upcase(d_religion)='BUDDHIST' then d_religion2='INDIAN';
    /* And so on */
run;

The proper way to provide sample data is https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Since I never download attachments, I'll take a guess here

 

data want;
    set have;
    if upcase(d_religion)='CATHOLIC' then d_religion2='CHRISTIAN';
    else if upcase(d_religion)='BUDDHIST' then d_religion2='INDIAN';
    /* And so on */
run;

The proper way to provide sample data is https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

--
Paige Miller
joachimg
Obsidian | Level 7
Amazing! Glad it was a command I haven't learned yet and not just me being dumb..... thank you so much! 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 504 views
  • 0 likes
  • 2 in conversation