BookmarkSubscribeRSS Feed
KDang
Fluorite | Level 6
Hi,

I'm using proc format as:

VALUE $ProvFmt
'P1' ='ON'
'P2' ='BC'
'P3' ='AB'
'P4' ='MB'
'P5' ='SK'
'P6' ='QC'
'P7' ='NS'
'P8' ='NB'
'P9' ='NL'
'P10'='PE'
'P11'='NT'
'P12'='YK'
'P13'='NU'

when I run frequencies on my data, the output goes in the order of

ON
BC
AB
MB
SK
QC
NS
NB
NL
PE
NT
YK
NU

How do I change my statement so the ouput goes in the following order:
BC
AB
SK
MB
ON
QC
NB
NS
NL
PE
NT
YK
NU

Thanks for your help!
6 REPLIES 6
deleted_user
Not applicable
hello,

if you use notsorted option for the value statement in proc format (and list the desired order (BC,AB,SK etc)) and run your output without order=formatted, you should get the wright result.

Marius
KDang
Fluorite | Level 6
Thanks for the reply, unfortunately that didnt seem to work..
Olivier
Pyrite | Level 9
Hi.
In addition to Marius' answer, you have to use both NOTSORTED option in the FORMAT procedure and PRELOADFMT + ORDER=DATA in a TABULATE procedure to get exactly what you want.
[pre]PROC FORMAT ;
VALUE $ProvFmt (NOTSORTED)
'P2' ='BC'
'P3' ='AB'
'P5' ='SK'
'P1' ='ON'
'P4' ='MB'
'P11'='NT'
'P12'='YK'
'P13'='NU'
'P10'='PE'
'P8' ='NB'
'P6' ='QC'
'P7' ='NS'
'P9' ='NL'
;
RUN ;
DATA work.test ;
DO i=1 TO 500 ;
num = ROUND(RAND("UNIFORM")*12+1) ;
product = CATS("P",num) ;
OUTPUT ;
END ;
FORMAT product $provfmt. ;
RUN ;
PROC TABULATE ;
CLASS product / PRELOADFMT ORDER=DATA ;
TABLE product, N ;
RUN ;[/pre]
Regards.
Olivier
KDang
Fluorite | Level 6
Thanks, that worked.

Just out of curiousity, is there a way to do it with PROC FREQ instead of Tabulate?
Olivier
Pyrite | Level 9
I don't think there is one, unfortunately. PROC FREQ is lacking the PRELOADFMT option.
data_null__
Jade | Level 19
How about using PROC SUMMARY which does support PRELOADFMT and then use ORDER=DATA in PROC FREQ.

[pre]
proc summary data=test nway;
class product / order=data preloadfmt;
output out=freqs;
run;
proc freq data=freqs order=data;
tables product;
weight _freq_;
run;


Cumulative Cumulati
product Frequency Percent Frequency Percen
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
BC 35 7.00 35 7.00
AB 58 11.60 93 18.60
SK 39 7.80 132 26.40
ON 23 4.60 155 31.00
MB 49 9.80 204 40.80
NT 42 8.40 246 49.20
YK 32 6.40 278 55.60
NU 21 4.20 299 59.80
PE 44 8.80 343 68.60
NB 28 5.60 371 74.20
QC 52 10.40 423 84.60
NS 50 10.00 473 94.60
NL 27 5.40 500 100.00
[/pre]

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1939 views
  • 0 likes
  • 4 in conversation