The SAS Output Delivery System and reporting techniques

Proc Report - Print all format values even where no data?

Accepted Solution Solved
Reply
Contributor
Posts: 47
Accepted Solution

Proc Report - Print all format values even where no data?

Hello

I'm running SAS 9.3

In the example below, no data exists where product="B".  But I'd like the proc report output to display "BRAVO, 0".

I know I can undertake additional data-steps to force the existence of the required observations, but I wondered if there was a solution within PROC REPORT itself?

proc format;

  value $ prodfull

  'A'='Alpha'

  'B'='Bravo'

  'C'='Charlie'

  ;

run;

data demodata;

  do i=1 to 33;

  do t='A','C';

  sales=i; product=t; output;

  sales=22;product="C"; output;

  end;

  end;

run;

Proc report data=work.demodata;

title 'How can I display zero sales for Product Bravo?';

column Product sales;

define product / group f=$prodfull. 'Product' ;

define sales / sum 'Sales';

run;title;


Accepted Solutions
Solution
‎01-22-2015 07:01 AM
Super User
Posts: 9,671

Re: Proc Report - Print all format values even where no data?

use completerows + preloadfmt

proc format;
  value $ prodfull
  'A'='Alpha'
  'B'='Bravo'
  'C'='Charlie'
  ;
run;
 
 
data demodata;
  do i=1 to 33;
  do t='A','C';
  sales=i; product=t; output;
  sales=22;product="C"; output;
  end;
  end;
run;
 
options missing='0'; 
Proc report data=work.demodata completerows  nowd;
title 'How can I display zero sales for Product Bravo?';
column Product sales;
define product / group f=$prodfull. preloadfmt 'Product' ;
define sales / sum 'Sales';
run;title;


Xia Keshan

Message was edited by: xia keshan

View solution in original post


All Replies
Super User
Super User
Posts: 7,392

Re: Proc Report - Print all format values even where no data?

Not as far as I know.  You could of course do a pro means with / mlf option to get the results.  Me personally I always generate the table as I want to see it in the output first, then do a proc report.  The reason is twofold, first it keeps the proc report minimal, and you have more options in datastep, secondly I need to keep the dataset so that someone else can QC it.

Solution
‎01-22-2015 07:01 AM
Super User
Posts: 9,671

Re: Proc Report - Print all format values even where no data?

use completerows + preloadfmt

proc format;
  value $ prodfull
  'A'='Alpha'
  'B'='Bravo'
  'C'='Charlie'
  ;
run;
 
 
data demodata;
  do i=1 to 33;
  do t='A','C';
  sales=i; product=t; output;
  sales=22;product="C"; output;
  end;
  end;
run;
 
options missing='0'; 
Proc report data=work.demodata completerows  nowd;
title 'How can I display zero sales for Product Bravo?';
column Product sales;
define product / group f=$prodfull. preloadfmt 'Product' ;
define sales / sum 'Sales';
run;title;


Xia Keshan

Message was edited by: xia keshan

Contributor
Posts: 47

Re: Proc Report - Print all format values even where no data?

Thanks Xia, that's really going to help keep my programs sleek.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 431 views
  • 0 likes
  • 3 in conversation