0
votes

I am trying to get frequency table from categorical variable. I get no output . error says my data are missing. here is my code :

data one;

input overweight $ hours;

if hours <= 2 then hours= 'low';

if hours > 2 then hours= 'high';

if hours= 'high' then d=1;

else d=0;

datalines;

yes    8.0
no     0.5
yes    2.0
yes    6.5
.
.
.
;
proc freq data=one order=data;

by hours;

table overweight*hours/cmh;

run;

Thanks

1
As noted below, you can't change a variable type dynamically in SAS. You can use a different name though, rename the HOURS to HOURS_CHAR or HOURS_CAT for example and then it will work fine. - Reeza

1 Answers

2
votes

You are not seeing data because you are attempting to assign a character string to a numeric variable.

if hours <= 2 then hours= 'low';
if hours > 2 then hours= 'high';

Doing this assigns a missing value to hours and since hours is a missing value you are not seeing any output.

If you were to change your code to use a numeric value for hours instead of text like:

if hours <= 2 then hours = 0;
if hours > 2 then hours = 1;

After this you will need to sort your dataset by hours and then you should see your output.