BookmarkSubscribeRSS Feed
RajasekharReddy
Fluorite | Level 6

Dear all ,

My requirement is generate table for all posibles missing value numbers by using proc freq and proc means for below data and output is given below

i tried with below code but i am not geeting exact output and missing two values in output ""American" and "Indian" please see output below i want

proc format;

value trt

1 = "Active"

0 = "Placebo";

value race

1 = "White"

2 = "Black"

3 = "Cocasion"

4="American"

5="Indain" ;

run;

ods listing close;

ods output crosstabfreqs=data ;

proc freq data=demog ;

tables trt*race/missing sparse;

format race race. ;

run;

ods output close;

ods listing;

options missing='_' ;

proc means data=demog ;

class race/preloadfmt ;

format race race. ;

var trt ;

run;

data ;

data demog;

label subjid = "Subject Number"

trt = "Treatment"

race = "Race" ;

input subjid trt race ;

cards;

101 0 3

102 1 1

103 1 2

104 0 1

105 1 3

106 0 1

201 1 3

202 0 1

203 1 2

204 0 1

205 1 3

206 1 1 ;

Run;

output;

Race

Treatment  Placebo

Treatment Active

White

4

2

black

0

1

cocasian

1

3

America

0

0

Indian

0

0

Thanks & Regards,

Rajasekhar Reddy

3 REPLIES 3
Reeza
Super User

Proc freq doesn't support PRELOADFMT in 9.3 at least. Proc tabulate will.

For Proc means use classdata option instead.

proc format;

value trt

1 = "Active"

0 = "Placebo";

value race

1 = "White"

2 = "Black"

3 = "Caucasian"

4="American"

5="Indain" ;

run;

data class_levels;

do race=1 to 5;

output;

end;

run;

proc means data=demog classdata=class_levels ;

class race;

format race race. ;

var trt ;

run;

proc tabulate data=demog;

class race trt/preloadfmt;

format race race. trt trt.;

table race, trt * N=''/printmiss;

run;

TomKari
Onyx | Level 15

If your tables will contain large numbers of cells, PROC FREQ will break down first because of volume. PROC TABULATE will handle a higher number of result cells, and PROC MEANS is the best.

For large result tables, if I can functionally use PROC MEANS that's my preference.

Tom

Tom
Super User Tom
Super User

To get MEANS/SUMMARY to generate all cells you need to include the COMPLETETYPES option.

proc summary data=demog(keep=race trt) nway  completetypes;

  class race trt/preloadfmt ;

  format race race. trt trt.;

  output out=summary ;

run;

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1805 views
  • 3 likes
  • 4 in conversation