BookmarkSubscribeRSS Feed
0 Likes

According to SAS Documentation, "An analysis variable is a numeric variable that is used to calculate a statistic for all the observations represented by a cell of the report." I would love to have some summary functions for character variables as well, such as coalesce or count.

Example Use Case

Given a dataset like this:

mtnbikerjoshua_0-1671117769070.png

Be able to create a report like this:

mtnbikerjoshua_1-1671118206705.png

 

data toprint;
  input groupvar $ acrossvar $ charvar $ numvar;
  datalines;
Group1 Across1 A 1
Group2 Across1 Q 4
Group1 Across2 T 1
Group2 Across2 F 7
;
run;

/* The desired report is easily created for a numeric variable */
proc report data=toprint;
  column groupvar numvar,acrossvar;
  define groupvar / group;
  define acrossvar / " " across;
  define numvar / " " analysis sum;
run;

/* But for a character variable you can only get a "stairstep" output */
proc report data=toprint;
  column groupvar charvar,acrossvar;
  define groupvar / order;
  define acrossvar / " " across;
  define cahrvar / " " display;
run;

/* The desired functionality might look something like the following */
/** This code does not work **/
proc report data=toprint;
  column groupvar charvar,acrossvar;
  define groupvar / group;
  define acrossvar / " " across;
  define charvar / " " analysis coalesce;
run;

 

mtnbikerjoshua_4-1671118571852.png

mtnbikerjoshua_3-1671118550164.png

In a pharmaceutical setting, groupvar might be usubjid, you might have parcat1 and param as across variables, and charvar might be avalc. This functionality would allow you to create a wide format listing of character data with very little work.

 

2 Comments
Cynthia_sas
SAS Super FREQ

Hi:

  This is already possible with PROC REPORT using a computed numeric value that you essentially "hide" with NOPRINT. When PROC REPORT has a numeric column that it can summarize, you can avoid the "stair-step" uncollapsed type of report just by adding a variable that contains a number.

Cynthia_sas_0-1671130059539.png

 

  In my example, I call the helper variable "dummyvar", because it really is just a dummy variable that is only ever going to hold the value 1. But having a numeric item on the report row allows groupvar to have a usage of GROUP and gives it a numeric value to summarize, so the character values appear correctly under Across1 and Across2.

  I have a different example of this type of collapsing in my paper, here: https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf See the example starting on page 4.

Cynthia

mtnbikerjoshua
Obsidian | Level 7

Hi Cynthia,

 

Thank you so much for your response! I actually looked at your paper multiple times, but somehow totally missed the clearly laid out solution to the exact problem I was having... I guess I should have read more closely. Anyway, I am very glad there is a simple way to do this.

 

I still think that the sort of native syntax I suggested would be a good idea, but since there is a simple workaround, I doubt SAS would find it worth the time to implement.

 

Joshua