Length of a numeric variable---already imported

#1
Hi,
I imported an excel file into SAS 9.3.
One of my variables is INCOME.
Running a proc freq, my income is listed out of order, according to the first number, so for instance, here is an example of my output (attached):



Do I need to re-import the excel datasheet with some kind of length statement, or is there another way to sort this variable, so that, 96 is listed first, etc.?

Thanks!
 

hlsmith

Less is more. Stay pure. Stay poor.
#2
It shouldn't be doing this. If you look at the variable info in the dataset or run proc contents - is SAS calling this a character variable instead of continuous? If so you have many options to remedy - best is probably reformatting in Excel.
 
#4
Ok, another question related to this.

I have variables that are numeric, but listed out of order, so that any integers are listed at the top, while any with decimal places are listed below.
(Please see below). For instance, 5-14 are listed prior to 5.1. And the data that was imported was all formatted to one decimal place.

I've rounded to nearest .1, but can't figure out how to get them listed in proper sequence. I'm sure it's simple, please help!
Thanks!

HbA1c Freq % Cum Cum
Freq %
5 1 0.06 1 0.06
6 32 2.03 33 2.09
7 39 2.47 72 4.56
8 40 2.53 112 7.09
9 15 0.95 127 8.04
10 18 1.14 145 9.18
11 8 0.51 153 9.69
12 4 0.25 157 9.94
13 2 0.13 159 10.07
14 18 1.14 177 11.21
5.1 1 0.06 178 11.27
5.2 6 0.38 184 11.65
5.3 7 0.44 191 12.1
5.4 5 0.32 196 12.41
5.5 11 0.7 207 13.11
5.6 13 0.82 220 13.93
 

hlsmith

Less is more. Stay pure. Stay poor.
#5
Are you familiar with proc contents? Once again, I would run:

proc contents data=?????;
var ?????;
run;

and see if the variable is formatted as numeric. Removing characters in the excel spreadsheet does not ensure it was imported as numeric data.
 
#6
Yeah, I did run proc contents, and the format is BEST12, which is default for a numeric format. So I am unsure why then the numeric variables are listed out of order.
 
#7
I also tried going the route of

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.
 

hlsmith

Less is more. Stay pure. Stay poor.
#9
Not following what your problem is, the order, the number of decimal places?

Code:
[FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]
[B][SIZE=2][FONT=Courier New][COLOR=#000080]data[/COLOR][/FONT][/SIZE][/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] test;[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]input[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] A B C D E;[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]datalines[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]5 1 0.06 1 0.06[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]6 32 2.03 33 2.09[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]7 39 2.47 72 4.56[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]8 40 2.53 112 7.09[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]9 15 0.95 127 8.04[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]10 18 1.14 145 9.18[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]11 8 0.51 153 9.69[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]12 4 0.25 157 9.94[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]13 2 0.13 159 10.07[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]14 18 1.14 177 11.21[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]5.1 1 0.06 178 11.27[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]5.2 6 0.38 184 11.65[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]5.3 7 0.44 191 12.1[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]5.4 5 0.32 196 12.41[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]5.5 11 0.7 207 13.11[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]5.6 13 0.82 220 13.93 [/FONT][/SIZE]
[SIZE=2][FONT=Courier New];[/FONT][/SIZE]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]run[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]proc[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]contents[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]run[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]proc[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]sort[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]data[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]=test;[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]by[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] c;[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]run[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]proc[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]print[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]data[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]=test;[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]var[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] C;[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]run[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]proc[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]freq[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]data[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]=test;[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]table[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] c;[/SIZE][/FONT]
[/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080][FONT=Courier New][SIZE=2][COLOR=#000080]run[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
[/SIZE][/FONT]
 
#10
Numeric variables will sort correctly. The person above is correct - it is a character variable. A cheap way to change it from character to numeric is to do the following:

CHar_Var=Char_Var+0;