Help using Base SAS procedures

order in Proc Tabulate

Reply
Super Contributor
Posts: 401

order in Proc Tabulate

Hi, I have inputed text data (see CODE1 below, and I want the CI1 to remain in the same order when I run it though proc tabulate.  But instead it sorts it as such (see OUTPUT1).  I'm using the TABULATE code (see CODE2).  thanks

CODE1:

if Vendor_1 < -0.20 then CI1 = '<=-20.1%';

else if Vendor_1 < -0.15 and Vendor_1 => -0.20 then CI1 = '-15.1% => and => -20%';

else if Vendor_1 < -0.12 and Vendor_1 => -0.15 then CI1 = '-12.1% => and => -15%';

else if Vendor_1 < -0.10 and Vendor_1 => -0.12 then CI1 = '-10.1% => and => -12%';

else if Vendor_1 < -0.08 and Vendor_1 => -0.10 then CI1 = '-8.1% => and => -10%';

else if Vendor_1 < -0.05 and Vendor_1 => -0.08 then CI1 = '-5.1% => and => -8%';

else if Vendor_1 <= 0 and Vendor_1 => -0.05 then CI1 = '0.0% => and => -5%';

else if Vendor_1 > 0 and Vendor_1 <= 0.05 then CI1 = '0.1% <= and <= 5%';

else if Vendor_1 > 0.05 and Vendor_1 <= 0.08 then CI1 = '5.1% <= and <= 8%';

else if Vendor_1 > 0.08 and Vendor_1 <= 0.10 then CI1 = '8.1% <= and <= 10%';

else if Vendor_1 > 0.10 and Vendor_1 <= 0.12 then CI1 = '10.1 <= and <= 12%';

else if Vendor_1 > 0.12 and Vendor_1 <= 0.15 then CI1 = '12.1% <= and <= 15%';

else if Vendor_1 > 0.15 then CI1 = '>15%'; else CI1 = 'ZZZ';

end;

end;

OUTPUT1:

-10.1% => and => -12%
-12.1% => and => -15%
-15.1% => and => -20%
-5.1% => and => -8%
-8.1% => and => -10%
0.0% => and => -5%
0.1% <= and <= 5%
10.1 <= and <= 12%
12.1% <= and <= 15%
5.1% <= and <= 8%
8.1% <= and <= 10%
<=-20.1%
>15%

CODE2:

PROC TABULATE data=Test;

CLASS USE_CI CI1 Vendor_1;

var count;

TABLE Vendor_1*CI1,pctn<CI1 all>  /rts=35;

RUN;

Super Contributor
Posts: 1,636

order in Proc Tabulate

changing code to:

proc tabulate data=test order=data;

Super Contributor
Posts: 401

order in Proc Tabulate

Doing that, I got :

>15%
-10.1% => and => -12%
<=-20.1%
-15.1% => and => -20%
-8.1% => and => -10%
0.1% <= and <= 5%
0.0% => and => -5%
-12.1% => and => -15%
5.1% <= and <= 8%
-5.1% => and => -8%
12.1% <= and <= 15%
8.1% <= and <= 10%
10.1 <= and <= 12%
Super User
Posts: 11,343

order in Proc Tabulate

For use with ORDER=DATA sometimes it helps to sort the data so the order is as expected.

Super Contributor
Posts: 1,636

order in Proc Tabulate

please sort your data by Vendor_1 , then run proc tabulate. something like this:

proc sort data=your_dataset out=temp;

by vender_1;

run;

proc tabulate data=temp order=data;

Super Contributor
Posts: 401

order in Proc Tabulate

Thank you.. worked fine.

Ask a Question
Discussion stats
  • 5 replies
  • 148 views
  • 0 likes
  • 3 in conversation