This document is an extension to the previous document detailing how to use the %unistats macro and will assume you have test datasets available.
You have to be aware of the logic. Once you have that clear in your
mind then it is easy. Here is the logic for not using "by" variables.
Call %titles
Select account data on population (dataset referred to as "acct" later) Call %popfmt Merge reporting data with acct dataset and keep the data that matches with the acct data (outut dataset referred to as "repdata" later) Call %openrep Call %unistats to produce the report from repdata Call %closerep |
Here is the logic for using "by" variables. Note the use of the
%nobs
and %getvalue macro.
If inside a macro, declare a local macro variable "byval" (for
example)
Call %titles Select account data on population (dataset referred to as "acct" later) Merge reporting data with acct dataset and keep the data that matches with the acct data (output dataset referred to as "repdata" later) Create a "by" value dataset from the acct dataset with just the unique "by" values in (dataset referred to as "bydset" later and "by" variable referred to as "byval" for this example) Call %openrep %do i=1 %to %nobs(bydset);
data acct2;
Run %popfmt on the acct2 dataset Call %unistats to produce the report from repdata subsetting on &byval %end; *% end of do loop -; Call %closerep |
/* Demonstrate %unistats: program 7 amended for a "by" variable
*/
options noovp nodate nonumber center missing=" " formchar='|_---|+|---+=|-/\<>*'; options sasautos=("C:\spectre\macros" SASAUTOS); options ls=78 ps=63; %*titles; %*- macro commented out -; title1; proc format;
proc sort data=sasuser.demog(where=(fascd=1))
data demog;
proc sort nodupkey data=demog(keep=invid) out=bydset;
%*openrep; %*- macro commented out -; %macro rep;
%popfmt(demog(where=(invid=&invid)),trtcd,uniqueid=patno invid) %unistats(dsin=demog(where=(invid=&invid)),total=yes,byvars=invid,
%end;
%rep; %*closerep; %*- macro commented out -; |
And here is the output shown for the first two invid's only.
---------------------------- INVESTIGATOR ID=1000 ----------------------------
______________________________________________________________________________
Number of Patients (%) /
Ambident Betamax
Gender
Race
Age (yrs)
Weight (kg)
Height (cm)
______________________________________________________________________________
Number of Patients (%) /
Ambident Betamax
Gender
Race
Age (yrs)
Weight (kg)
Height (cm)
|
Use the "Back" button of your browser to return to the previous page