|
|
 | | From: | Littleinfo | | Subject: | How to generate a report like this...(Revised) | | Date: | 22 Jan 2005 00:42:36 -0800 |
|
|
 | Dear all SAS-experts,
I've a table similar to Table 1 and would like to generate a report/table similar to Table 2. How can I do that in SAS if I've only got SAS/BASE?
Table 1 id segment indicator amount sales 10002 A 1,000 111 10003 B 20,000 333 10004 C 1 500,000 222 10005 D 555 444 10006 C 1 487,878 555 10007 D 5,555 666 10008 A 7,877 555 10009 C 1 45,556 666 10010 A 2,222 222 10011 B 12,345 111 10012 C 8,855 111 10013 D 7,777 333 10014 B 1 47,777 555 10015 A 5,588 444 10016 C 45 666
Table 2
Sales Segment |Segment and with Indicator=1 | A B C D | A B C D ------------------------------------------------------------------- 111 | 222 | 333 | 444 | 555 | 666 |
Thanks in advances!
regards littleinfo
|
|
 | | From: | Pudding Man | | Subject: | Re: How to generate a report like this...(Revised) | | Date: | 22 Jan 05 23:50:20 GMT |
|
|
 | It's not 100% clear precisely what you want, here, but I might be able to put something in the ballpark ...
One (traditional SAS) approach to a custom report such as this uses data step(s), FILE PRINT and PUT statements. Following semi-crude code illustrates:
data t1; input +8 segment $ ind $17 @32 amount :comma8. sales :3.; cards; 10002 A 1,000 111 10003 B 20,000 333 10004 C 1 500,000 222 10005 D 555 444 10006 C 1 487,878 555 10007 D 5,555 666 10008 A 7,877 555 10009 C 1 45,556 666 10010 A 2,222 222 10011 B 12,345 111 10012 C 8,855 111 10013 D 7,777 333 10014 B 1 47,777 555 10015 A 5,588 444 10016 C 45 666 ; run;
proc sort; by sales; run;
proc format; invalue abcd 'A' = 1 'B' = 2 'C' = 3 'D' = 4; run;
data t2(keep = sales a--d1); array ind0 (4) a b c d; array ind01(4) a1 b1 c1 d1;
do until (last.sales); set t1; by sales; ss = input(segment, abcd.); if ind = ' ' then ind0(ss) = sum(ind0(ss), amount); ind01(ss) = sum(ind01(ss), amount); end;
run;
options missing = ' '; data _null_; array ind01(4) a1 b1 c1 d1; file print; length dash $73; dash = repeat('-', 72);
put 'Sales Segment (Ind = 0) | Segment (Ind = 0 or 1) ' /+3 ' A B C D | A B C D' / dash;
do until (e1); set t2 end = e1; put sales (a b c d) (8.) ' |' @; do i = 1 to dim(ind01); if ind01(i) then put @(43 + (i - 1) * 8) ind01(i) @; end; put; end;
stop; run;
If this approach is chosen and the report will run for many pages, see SAS doc for FILE PRINT HEADER=.
Hope it hep's ...
Prost, Puddin'
****************************************************** *** Puddin' Man PuddingDotMan at GmailDotCom *** ******************************************************;
"Some got six months, some got one solid year. But me and my buddy, we got a lifetime heah." -from "Viola Lee Blues", Noah Lewis/Cannons Jug Stompers, maybe 1927
On Sat, 22 Jan 2005 00:42:36 -0800, Littleinfo wrote: > Dear all SAS-experts, > > I've a table similar to Table 1 and would like to generate a report/table > similar to Table 2. How can I do that in SAS if I've only got SAS/BASE? > > Table 1 > id segment indicator amount sales > 10002 A 1,000 111 > 10003 B 20,000 333 > 10004 C 1 500,000 222 > 10005 D 555 444 > 10006 C 1 487,878 555 > 10007 D 5,555 666 > 10008 A 7,877 555 > 10009 C 1 45,556 666 > 10010 A 2,222 222 > 10011 B 12,345 111 > 10012 C 8,855 111 > 10013 D 7,777 333 > 10014 B 1 47,777 555 > 10015 A 5,588 444 > 10016 C 45 666 > > Table 2 > > Sales Segment |Segment and with Indicator=1 | > A B C D | A B C D > ------------------------------------------------------------------- > 111 | > 222 | > 333 | > 444 | > 555 | > 666 | > > Thanks in advances! > > regards > littleinfo >
|
|
|