Wow. How much trouble am I having with these Proc Reports.
I am hoping that someone can help me once again.
The following code allows me to produce a report with all my coverage codes as variables, however the observations displayed are simply a count of how many times the each coveragecode appears in the dataset I am using. What I wish to do is place my calculated frequency in these colums. Is this possible? If so, can someone help me with the syntax.
Thank you very much.
options nodate pageno=1 linesize=64
proc report Data=Merged Out = Frequency headline headskip;
column exposmth coveragecode EarnedCov Claimcount Frequency;
define coveragecode / Across ;
define exposmth / Group;
define EarnedCov / Analysis Sum noprint;
define Claimcount / Analysis Sum noprint ;
define Frequency / Computed format = percent9.2;
Frequency = Claimcount.sum / EarnedCov.sum;
Message was edited by: Scottcom4
Wow, what a difference a comma and some parentheses can make in your program!
Basically, you will only get the COUNT or the N in an ACROSS scenario, unless you "cross" or "nest" your ACROSS variable with other report items or statistics. So, for example, if you wanted one item, it would be:
[pre] column groupvar acrossvar,onevar; [/pre]
if it was 2 items, it would be:
[pre] column groupvar acrossvar,(onevar twovar); [/pre]
and if it was 2 items and a computed item, it might be:
column groupvar acrossvar,(onevar twovar calcvar);
define groupvar / group;
define acrossvar / across;
define onevar / sum;
define twovar / sum;
define calcvar / computed;
And, now that you've learned about onevar.sum and twovar.sum in a COMPUTE block, you have to learn something else about ACROSS usage. Proc Report has yet -another- way to reference across variables. So, let's say that, in the above fake example, that acrossvar has 3 possible values: XXX, YYY and ZZZ.
Essentially, you will have a report that looks like this:
Now Proc Report can get easily confused. If you plan to calculate CALCVAR by adding ONEVAR and TWOVAR -- how does Proc REPORT know that you want the ONEVAR and TWOVAR for XXX versus the ONEVAR and TWOVAR for YYY??? So, in this case, the simple ONEVAR.SUM and TWOVAR.SUM will not make PROC REPORT happy.
Essentially, Proc Report goes through a setup phase when it gets started, and if you have any reference to ACROSS usage, then PROC REPORT figures out how many values you have for the across variables (in this case, 3), how many variables or items you have nested under the across variable (in this case, also 3) and how many items you have -before- the first ACROSS variable value (in this case -- 1 for groupvar). Then it assigns absolute column numbers to every one of the columns that comes from nesting within the ACROSS. Like this:
---------XXX--------- ---------YYY--------- ---------ZZZ---------
groupvar onevar twovar calcvar onevar twovar calcvar onevar twovar calcvar
AAA 111 222 333 110 220 330 100 200 300
BBB 11 22 33 10 20 30 20 10 30
| | | | | | | | | |
v v v v v v v v v v
first col _c2_ _c3_ _c4_ _c5_ _c6_ _c7_ _c8_ _c9_ _c10_
(these are now the "absolute" column names that REPORT wants you to use)
So, groupvar is conceptually column 1, but there's no confusion about how to reference it, so it counts as 1, but doesn't get an absolute name. However, starting with the column for ONEVAR under XXX, the column name internally becomes known as _c2_, and then TWOVAR under XXX becomes _c3_ and CALCVAR under XXX becomes _c4_, etc, etc. Even if you use NOPRINT to hide ONEVAR and TWOVAR, they still get absolute names assigned to them.
That means your compute block would look like:
_c4_ = _c2_ + _c3_;
_c7_ = _c5_ + _c6_;
_c10_ = _c8_ + _c9_;