- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then in my proc output, variable A is ordered as follows
0
1
11
2
22
3
33
4
44
but I would like it to be ordered as follows
0
1
2
3
4
11
22
33
44
Any help is appreciated!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The SORTSEQ option of PROC SORT allows you to sort your data, using an option to tell SORT to sort by the numeric value of a field, instead of the character representation of the field. (The example in the doc explains that you would use NUMERIC_COLLATION=ON when you wanted to show "8 Main Street" sorted above "45 Main Street" (with NUMERIC_COLLATION=OFF, then the "45 Main Street" would come first)
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146878.htm
Once you have the data sorted, then you need to tell PROC FREQ to use the sorted order, or DATA order, as shown in the output from the program below.
cynthia
[pre]
data myvars;
infile datalines;
input grp $ vara $ varb;
return;
datalines;
aaa 0 10
bbb 1 20
ccc 2 30
ddd 3 40
eee 11 40
fff 22 30
ggg 33 20
hhh 44 10
;
run;
ods listing;
proc freq data=myvars;
title '1) proc freq before sort';
table grp vara varb;
run;
proc sort data=myvars sortseq=linguistic(numeric_collation=on);
by grp vara varb;
run;
ods listing;
proc freq data=myvars order=data;
title '2) proc freq after sort with order=data';
table grp vara varb;
run;
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
By the way, I think you meant an ascending order. 🙂
/* test data */
data one;
length c $2 n 8;
input c @@;
n = input(c, best.);
cards;
0 1 11 2 22 3 33 4 44
;
run;
/* a view that right aligns character vars */
data two/view=two;
set one;
array cs _character_;
do over cs;
cs = right(cs);
end;
run;
proc freq data=two;
run;
/* on lst
Cumulative Cumulative
c Frequency Percent Frequency Percent
-------------------------------------------------------
0 1 11.11 1 11.11
1 1 11.11 2 22.22
2 1 11.11 3 33.33
3 1 11.11 4 44.44
4 1 11.11 5 55.56
11 1 11.11 6 66.67
22 1 11.11 7 77.78
33 1 11.11 8 88.89
44 1 11.11 9 100.00
Cumulative Cumulative
n Frequency Percent Frequency Percent
-------------------------------------------------------
0 1 11.11 1 11.11
1 1 11.11 2 22.22
2 1 11.11 3 33.33
3 1 11.11 4 44.44
4 1 11.11 5 55.56
11 1 11.11 6 66.67
22 1 11.11 7 77.78
33 1 11.11 8 88.89
44 1 11.11 9 100.00
*/