problem with order of numeric values in proc freq

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

problem with order of numeric values in proc freq

Hi, I have a numeric variable (continuous), format BEST12.

When running code for a proc freq, i.e.

proc freq     data=joe.fdata4     order=formatted;

tables age hba1c;

run;

my output lists all values with a .0 first, above any values with non-whole integer.

Screen shot 2013-06-13 at 3.34.25 PM.png

Since it is a numeric format, can anyone tell me how to fix? I've even tried using

data joe.fdata4; set joe.fdata4;

hba1c=input(hba1c,2.1);

run;

to try and input the variable with the w.d statement, but then all values in the variable are missing. So this can't be right.

Thank you


Accepted Solutions
Solution
‎06-13-2013 04:51 PM
Super User
Posts: 19,850

Re: problem with order of numeric values in proc freq

Posted in reply to joebaker7

Do it without the order=formatted option. I think I got the same with that option selected, but without it works the way you expected.

Also, the Format of 2.1 would be too small to show 5.4 properly.

data class;

    set sashelp.class;

    retain test 0.1;

    if age=14 then age=age+test;

    test+0.1;

    if name='Alfred' then age=1.8;

    temp=put(age, 2.1);

run;

proc freq data=class;

table age temp;

run;

proc freq data=class order=formatted;

table age temp;

run;

View solution in original post


All Replies
Super User
Posts: 19,850

Re: problem with order of numeric values in proc freq

Posted in reply to joebaker7

Can you post the output of proc contents from your dataset for that variable, type and format please?

proc contents data=joe.fdata4;

run;

Occasional Contributor
Posts: 13

Re: problem with order of numeric values in proc freq

Yes, here, with HbA1c listed at bottom:

Screen shot 2013-06-13 at 3.44.32 PM.png

Screen shot 2013-06-13 at 3.44.15 PM.png

Respected Advisor
Posts: 3,156

Re: problem with order of numeric values in proc freq

Posted in reply to joebaker7

If you are trying to analyze continuous variable as ordinal variable, you would need more than build-in SAS format. I would suggest that you carefully choose your bin width, then run a proc format, then do a proc freq, based on your new format.

Just my 2cents,

Haikuo

Occasional Contributor
Posts: 13

Re: problem with order of numeric values in proc freq

First I am trying to look at the distribution before creating a new ordinal variable from it, but I also need to do analysis with it as a continuous variable, so I'd like to know that the values are correctly ordered.

Solution
‎06-13-2013 04:51 PM
Super User
Posts: 19,850

Re: problem with order of numeric values in proc freq

Posted in reply to joebaker7

Do it without the order=formatted option. I think I got the same with that option selected, but without it works the way you expected.

Also, the Format of 2.1 would be too small to show 5.4 properly.

data class;

    set sashelp.class;

    retain test 0.1;

    if age=14 then age=age+test;

    test+0.1;

    if name='Alfred' then age=1.8;

    temp=put(age, 2.1);

run;

proc freq data=class;

table age temp;

run;

proc freq data=class order=formatted;

table age temp;

run;

Occasional Contributor
Posts: 13

Re: problem with order of numeric values in proc freq

Oh man it was just the

order=formatted

So the data is fine then.  When I do regression analysis, I'll know that the HbA1c variable is truly ordered.

Thanks

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 298 views
  • 0 likes
  • 3 in conversation