BookmarkSubscribeRSS Feed
geneva
Calcite | Level 5

Just learning SAS EG, and this has me completely stumped. I would like to recode a variable dependent on the value of a different variable for the same row. The example I am working with is this: Males do not menstruate, so I would want to exclude the age of menstruation for Males.  I attempted to create a recoded column marking the age of menstruation as missing for males using a CASE statement, but my new column had 1s and 0s instead of the original value. The advanced expression was:

CASE

WHEN 'Gender' = 'M' THEN 'AgeMenst' = .

ELSE 'AgeMenst' = 'AgeMenst'

END

What am I doing wrong? I have tried multiple different combinations. I've tried leaving out the ELSE statement.

8 REPLIES 8
Reeza
Super User

Drop some of the quotes, and a case statement is usually formatted as below:

CASE

WHEN Gender = 'M' THEN  .

ELSE AgeMenst

END as AgeMenst

geneva
Calcite | Level 5

This is what I get when using that format (the variable names are actually 'MnstAge Recoded' and 'Gender Recoded'). Any ideas? Have also tried with 'M' instead of M.

enterprise guide issue.png

ChrisHemedinger
Community Manager

This looks like a code generation error with non-standard variables names, and I'm pretty sure that it has been addressed in a SAS Enterprise Guide hotifx.  What version of SAS Enterprise Guide are you running?  Check to make sure that you have the latest fixes.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
geneva
Calcite | Level 5

I'm using 4.3. I apologize, because I'm pretty new to this--is there a fix for this version, or would I be better off renaming my variables?

art297
Opal | Level 21

Are those actually your variable names? SAS variable names can't contain spaces or special characters unless you have the system option validvarname set to any, which isn't recommended.

Is age already calculated and, if so, what is the variable name?

Reeza
Super User

Then try leaving the quote but making the other changes, and storing it in a new variable.

CASE

WHEN 'Gender Recoded' = 'M' THEN  .

ELSE 'MnstAge Recoded'

END as New_Age_Menst

DaveBirch
Obsidian | Level 7

Reeza's code still needs a little adjustment:

CASE

WHEN 'Gender Recoded'n = 'M' THEN  .

ELSE 'MnstAge Recoded'n

END as New_Age_Menst

As Arthur noted, SAS variable names don't normally contain spaces or special characters.  If you want to refer to variables with a space in the name you need to surround the name with quote marks and follow it with the n modifier.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 1162 views
  • 4 likes
  • 5 in conversation