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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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