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
3705 | 74.32 | 3705 | 74.32 |
1280 | 25.68 | 4985 | 100.00 |
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;
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;
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;
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.