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

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!!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

7 REPLIES 7
Reeza
Super User

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.

jenim514
Pyrite | Level 9

@Reeza the conditions seem fine

Table of MARITAL_STATUS by sponsor_sex
MARITAL_STATUS sponsor_sex
FEMALE MALE Total
 
0
0.00
0.00
0.00
40
0.00
100.00
0.00
40
0.00
 
 
ANNULLED
196
0.01
53.85
0.08
168
0.01
46.15
0.01
364
0.01
 
 
DIVORCED
49215
1.71
27.56
20.45
129382
4.49
72.44
4.90
178597
6.20
 
 
LEGALLY SEPARATED
444
0.02
18.98
0.18
1895
0.07
81.02
0.07
2339
0.08
 
 
MARRIED
151768
5.27
5.87
63.06
2434738
84.58
94.13
92.29
2586506
89.85
 
 
NEVER MARRIED
37612
1.31
35.03
15.63
69764
2.42
64.97
2.64
107376
3.73
 
 
WIDOWED
1425
0.05
40.94
0.59
2056
0.07
59.06
0.08
3481
0.12
 
 
Total
240660
8.36
2638043
91.64
2878703
100.00
Reeza
Super User

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.

jenim514
Pyrite | Level 9

@Reeza  ah, yes.  There is formatting applied.  So I need to use the original values before formatting?

Reeza
Super User

Yes

Reeza
Super User

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.

jenim514
Pyrite | Level 9
lol. "yes" is a great answer! I changed the solution 🙂

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!

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.

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
  • 7 replies
  • 4260 views
  • 0 likes
  • 2 in conversation