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

This should be fairly simple.

Trying to create a new variable for two groups separately.

For group a:

if diagn =0 or 1, then comorb=0; 

if diagn >=2 then comorb=1;

 

For group b:

if diagn =0 then comorb=0; 

if diagn >=1 then comorb=1;

 

The syntax for group2 works fine.

 

Here is my syntax for group1:

data x;

set x;

if group='a' then do;

if diagn =0 or diagn=1 then comorb=0;

else if diagn >=2 then comorb=1;

end;

 

This syntax does not calculate the comorb variable at all.

 

Any ideas on what might be wrong and how to correct it? 

Thank you! 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
NinaWestern
Obsidian | Level 7
Yes, there is a variable named "group", with a and b as its values.

The log has no errors.

View solution in original post

4 REPLIES 4
biopharma
Quartz | Level 8
Can you create a sample dataset with what you HAVE? Then present another dataset with what you WANT. Look how some posters have done this in a datastep and show.

If I were to take a wild guess, this condition is not met as specified.
if group='a' then do;

Try specifying this as
if upcase(group)="A" then do;
Shmuel
Garnet | Level 18

You haven't posted neither the log nor sample of your imput,

so it is impossible to know what is the mistake.

 

Is there a variable  named GROUP in your input dataset ?

 

NinaWestern
Obsidian | Level 7
Yes, there is a variable named "group", with a and b as its values.

The log has no errors.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1384 views
  • 0 likes
  • 4 in conversation