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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.