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

Hi,

I am having a trouble with my if then else statements,

I wrote

data all_1;
set total;
if hud080=. then h_count=.;
else if hud080=77777 then h_count= .;
else if hud080=99999 then h_count=.;
else if huq071=1 and hud080=1 then h_count=1;
else if huq071=1 and hud080 in (2,3,4,5,6) then h_count=2;

else if huq071=2 then h_count=0;
run;

 

Then my output for proc freq does not have h_count=0. Could anyone explain why h_count=0 is missing ?  Thanks

SAS Output

h_count Frequency Percent CumulativeFrequency CumulativePercent12Frequency Missing = 45980 
370574.32370574.32
128025.684985100.00
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The IF/THEN statements look OK.  Maybe the problem is with the data.  Do you actually have any observations that have 2 as the value of HUQ071?

 

Here's a good way to check what is in your data:

 

proc format;

value check .='Missing'   77777 = '77777'  99999='99999'   other='Valid';

run;

 

proc freq data=have;

tables HUQ071 * HUD080 / missing;

format HUD080 check. ;

run;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

No, we can't tell you why that is, you have not shown any test data.  SAS is based on data, without that part the logic doesn't do anything.  At a guess:

else if huq071=2 then h_count=0;

This condition is never met.

Maybe you meant:

else h_count=0;

 

Astounding
PROC Star

The IF/THEN statements look OK.  Maybe the problem is with the data.  Do you actually have any observations that have 2 as the value of HUQ071?

 

Here's a good way to check what is in your data:

 

proc format;

value check .='Missing'   77777 = '77777'  99999='99999'   other='Valid';

run;

 

proc freq data=have;

tables HUQ071 * HUD080 / missing;

format HUD080 check. ;

run;

ballardw
Super User

If you have many values for each of the two variables this modification of @Astounding's Proc freq may be of interest:

 

proc freq data=have;

tables HUQ071 * HUD080 / list nopercent missing;

 

run;

 

The LIST option creates one row per combination instead of the large two dimensional table and suppresses all of the percentages which I seldom find helpful in identifying data combinations.

 

 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 899 views
  • 0 likes
  • 4 in conversation