The SAS Output Delivery System and reporting techniques

Creating a Time Series Template with ODS

Reply
Occasional Contributor CMC
Occasional Contributor
Posts: 7

Creating a Time Series Template with ODS

Hi, I need to create a time series report in excel off of a SAS dataset.  The collumns will be each of the past 13 months and the rows will contain ~30 different descriptive statistics and their values for the rolling past 13 months.  One problem I encounter are some of the descriptive statistics are in percent format, other are numeric, etc.  Can someone please send me to a location of white paper or some other source that shows how to create such a report?  Most of the ODS reporting templates I've seen on the Internet have been somewhat simplistic, with uniform character formats in the collumns, etc  Thanks for any help.

Contributor
Posts: 42

Creating a Time Series Template with ODS

I think you need to convert your numerics to character fields with the proper formats.  This is just made up data - but I think you want to do something along these lines:

data work.class;

set sashelp.class;

format height2 ratio2 $32.;

   if height>60 then height2=put (height,dollar6.2);else

   if height <60 and height >57 then height2=put (height,comma6.2);else

    height2=put (height,percent6.2);

ratio=height/weight;

if ratio > .7 then ratio2 = put (ratio,percent6.2);else ratio2=put (ratio,dollar6.2);

run;

ods HTML4 file='c:\temp\excelreport.xls';

  proc report data=work.class  nowd LS=160 PS=50 SPLIT="*" contents=''

        style(report)={ bordercolor=grey font_size=11pt }

        style(column)={ bordercolor=#ddddff font_size=11pt bordercolor=grey  cellspacing=1}

        style(header)={background=#000075 foreground=white cellheight=40 font_size=12pt};

column  name sex age height2 weight ratio2 ;

define name / 'Name';

define sex / 'Sex';

define age / 'Age';

define height2 / display 'Height' ;

define weight / display 'weight' format=comma6.2;

define ratio2  / display  'Ratio';

run;

ods _all_ close;

This can give you a mixed format within a column.

NameSexAgeHeightweightRatio
AlfredM14$69.00112.50$0.61
AliceF136E3%84.00$0.67
BarbaraF13$65.3098.00$0.67
CarolF14$62.80102.50$0.61
HenryM14$63.50102.50$0.62
JamesM1257.3083.00$0.69
JaneF1259.8084.5071%
JanetF15$62.50112.50$0.56
JeffreyM13$62.5084.0074%
JohnM1259.0099.50$0.59
JoyceF115E3%50.50102%
JudyF14$64.3090.0071%
LouiseF126E3%77.0073%
MaryF15$66.50112.00$0.59
PhilipM16$72.00150.00$0.48
RobertM12$64.80128.00$0.51
RonaldM15$67.00133.00$0.50
ThomasM1157.5085.00$0.68
WilliamM15$66.50112.00$0.59
SAS Super FREQ
Posts: 8,862

Re: Creating a Time Series Template with ODS

Hi:

  You can actually do a lot of this formatting in a COMPUTE block without creating character versions of the variables. See the program below. It doesn't do the exact same things, but should be enough to give you an idea of how it would be done.

  If you want something like this demographic example, on the other hand:

Gender        N (PctN)  Age Range

     F        9 (47%)    11-15

     M       10 (53%)    11-16

where you have 2 statistics (N and PctN) concatenated together in 1 column on the report or the min/max of age formatted with a dash between them, then you might need to create a character variable prior to your report step or PROC REPORT might be able to compute the character variable for you. I showed an example (several examples) of doing this in my SUGI paper entitled "Creating Complex Reports", which you can find by searching support.sas.com web site. Also, the second step below produces the above example report (with N/PctN and Age Range).

cynthia

ods listing close;

ods html file='c:\temp\diff_fmt.html' style=sasweb;

proc report data=sashelp.class nowd;

   column name sex age height weight ratio;

   define name / order;

   define age / display;

   define height /sum;

   define weight / sum;

   define ratio /computed f=percent9.2;

   compute height;

     if sex = 'F' then do;

        call define(_col_,'format','percent9.2');

     end;

   endcomp;

   compute ratio;

     ratio = height.sum / weight.sum;

     if ratio gt .7 then do;

       call define(_col_,'format','dollar9.2');

     end;

   endcomp;

run;

 

ods html close;

ods html file='c:\temp\calc_cols.html' style=sasweb;

proc report data=sashelp.class nowd;

   column sex n pctn dispstats age=minage age=maxage disprange;

   define sex / group;

   define n / noprint;

   define pctn / noprint;

   define minage / min noprint;

   define maxage / max noprint;

   define dispstats /computed 'N (PctN)'

          style(column)={just=r};

   define disprange / computed 'Age Range'

          style(column)={just=r};

   compute dispstats/ character length=20;

     dispstats = cat(put(n,2.0),' (',put(pctn,percent6.),')');

   endcomp;

   compute disprange/ character length=20;

     disprange = catx('-',put(minage,2.0),put(maxage,2.0));

   endcomp;

run;

 

ods html close;

Ask a Question
Discussion stats
  • 2 replies
  • 293 views
  • 1 like
  • 3 in conversation