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

Good Afternoon,

 

I'm developing a list of conditions to see if my dataset is producing any non-logical combinations.

 

For each row we need to look in three columns and if the criteria is met we assign a value of 'Ok', if not we leave it blank.

 

I can not provide test data but below gives you a snippet of what I'm trying to do.

 

What I've noticed that in certain cases SAS is assigning a value of 'Ok', even though some records don't meet the criteria to be included.

 

An example of which is a cod value='C22'  which isn't included in my list of clauses but is being assigned as meeting it. Does anyone have an idea why this is the case?

 

data second;
retain value cod sex ageatdeath;
set first;
*List of all the condition caluses;
if cod="A33" and sex in('M','F') and ageatdeath <=1 then Value='OK';
if cod="A34" and sex in('F') and ageatdeath >=12 and ageatdeath <=55 then value='OK';
if cod="A500" and sex in('M','F') and ageatdeath >=0 and ageatdeath <=2 then value='OK';
if cod="C20" and sex in('M','F') and ageatdeath >=0 and ageatdeath <=2 then value='OK';
if cod="C23" and sex in('M','F') and ageatdeath >=0 and ageatdeath <=2 then value='OK';
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I can not provide test data but below gives you a snippet of what I'm trying to do.

 

Why not? An example that you make up that only uses the variables in the code should not reveal any sensitive information.

 

Here's an example

data have;
   input cod $ sex $ ageatdeath;
datalines;
A33 M 15
A33 F 1
A33 F 15
A33 M 1
A33 O 15
A33 O 1
A34 M 15
A34 F 1
A34 F 15
A34 M 1
A34 O 15
A34 O 1
C20 M 15
C20 F 1
C20 F 15
C20 M 1
C20 O 15
C20 O 1
;

Example data only needs to demonstrate values used in your question. Some problem descriptions should include whether other values are to be on the observations of the result but values aren't needed, or similar dummy could be included.

 

What did you think the RETAIN statement was going to do?

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Remove the RETAIN statement.

--
Paige Miller
ballardw
Super User

I can not provide test data but below gives you a snippet of what I'm trying to do.

 

Why not? An example that you make up that only uses the variables in the code should not reveal any sensitive information.

 

Here's an example

data have;
   input cod $ sex $ ageatdeath;
datalines;
A33 M 15
A33 F 1
A33 F 15
A33 M 1
A33 O 15
A33 O 1
A34 M 15
A34 F 1
A34 F 15
A34 M 1
A34 O 15
A34 O 1
C20 M 15
C20 F 1
C20 F 15
C20 M 1
C20 O 15
C20 O 1
;

Example data only needs to demonstrate values used in your question. Some problem descriptions should include whether other values are to be on the observations of the result but values aren't needed, or similar dummy could be included.

 

What did you think the RETAIN statement was going to do?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 954 views
  • 3 likes
  • 3 in conversation