Hi! I need help troubleshooting what seems to be an easy conditional statement. I need to create a table of married males, so I am using an if, then statement to output results. However, I am getting zero observations once the syntax completes running (this is incorrect).
Here is the code I am using.
data want;
set have;
if MARITAL_STATUS eq 'MARRIED' and SPONSOR_SEX eq 'MALE' then output;
else delete;
run;
I've also tried using a where statement, and also got zero observations and getting this note
WHERE 0 /* an obviously FALSE WHERE clause */ ;
data want;
set have;
where MARITAL_STATUS eq 'MARRIED' and SPONSOR_SEX eq 'MALE';
run;
Any assistance is apprciated!!
Next step...proc contents on the dataset. Look for custom formats on the two variables.
Do you have a format applied that is displaying the variables as Male/Married, when it's actually 0/1 or 1/2/3/4 etc?
If so, you need to use the underlying values in your filtering query.
Test your conditions with a proc freq
proc freq data=have;
table marital_status*sponsor_sex/missing;
run;
If you can't figure it out past here, post the output from the proc freq.
@Reeza the conditions seem fine
Table of MARITAL_STATUS by sponsor_sex | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MARITAL_STATUS | sponsor_sex | ||||||||||||||
FEMALE | MALE | Total | |||||||||||||
|
|
|
|||||||||||||
ANNULLED |
|
|
|
||||||||||||
DIVORCED |
|
|
|
||||||||||||
LEGALLY SEPARATED |
|
|
|
||||||||||||
MARRIED |
|
|
|
||||||||||||
NEVER MARRIED |
|
|
|
||||||||||||
WIDOWED |
|
|
|
||||||||||||
Total |
|
|
|
Next step...proc contents on the dataset. Look for custom formats on the two variables.
Do you have a format applied that is displaying the variables as Male/Married, when it's actually 0/1 or 1/2/3/4 etc?
If so, you need to use the underlying values in your filtering query.
@Reeza ah, yes. There is formatting applied. So I need to use the original values before formatting?
Yes
Best marked answer I've received so far. If you can change it, I might consider changing correct answer to the one about running proc contents and checking for custom formats.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.