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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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