| Date: | Wed, 14 Apr 2004 16:15:10 -0400 |
| Reply-To: | Jonas Bilenas <Jonas.Bilenas@CHASE.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Jonas Bilenas <Jonas.Bilenas@CHASE.COM> |
| Subject: | Re: Any procedure to get the percentage and sum |
|---|
To use formats to make it prettier, try the following modifcations to the
tabulate code provided by Dianne.
proc format;
picture pct (round) low - < 0 ='00009.99%' (prefix='-')
0 - high ='00009.99%'
;
proc tabulate data=old noseps formachar=' ';
class id ;
var amount ;
table (all id),
amount*(sum*f=dollar12.2 pctsum*f=pct8.)
/rts=15;
run;
OUTPUT:
Amount
Sum PctSum
All $16,000.00 100.00%
ID
1 $6,000.00 37.50%
2 $1,000.00 6.25%
3 $9,000.00 56.25%
On Fri, 9 Apr 2004 10:52:17 -0400, Dianne Rhodes <RHODESD1@WESTAT.COM>
wrote:
>How about proc tabulate? You can mess around with the formats to make it
>prettier.
>
>proc tabulate data=old ;
>class id ;
>var amount ;
>table (all id),
> amount*(sum pctsum)
> ;
>run;
>
>Yields :
>
>
> --------------------------------------------------------
> | | Amount |
> | |-------------------------|
> | | Sum | PctSum |
> |----------------------------+------------+------------|
> |All | 16000.00| 100.00|
> |----------------------------+------------+------------|
> |ID | | |
> |----------------------------| | |
> |1 | 6000.00| 37.50|
> |----------------------------+------------+------------|
> |2 | 1000.00| 6.25|
> |----------------------------+------------+------------|
> |3 | 9000.00| 56.25|
> --------------------------------------------------------
>
>Dianne Louise Rhodes
>Sr. Systems Analyst
>Westat
>
>
>> -----Original Message-----
>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On
>> Behalf Of sreevatsan
>> Sent: Friday, April 09, 2004 6:48 PM
>> To: SAS-L@LISTSERV.UGA.EDU
>> Subject: Any procedure to get the percentage and sum
>>
>>
>> Hi guys,
>> Thanks in advance for the solution
>>
>> Is there any procedure to get the Percentage and Sum at one time.
>>
>> The output of the program should be displayed like this
>>
>> Obs ID Amount Percent
>> 1 16000 100.00
>> 2 1 6000 37.50
>> 3 2 1000 6.25
>> 4 3 9000 56.25
>>
>> To achieve this I have written a lengthy code.
>>
>> data old;
>> infile cards;
>> input ID $ Date DDMMYY8. Amount 5.;
>> FORMAT DATE DDMMYY8.;
>> cards;
>>
>> 1 01/01/04 1000
>> 1 03/01/04 2000
>> 1 27/01/04 3000
>> 2 02/01/04 1000
>> 3 01/01/04 2000
>> 3 02/01/04 3000
>> 3 16/01/04 4000
>> ;
>>
>>
>> proc summary data = old;
>> class Id;
>> var Amount;
>> OUTPUT OUT = new(drop = _freq_ _type_) sum=;
>> run;
>>
>> data new1;
>> set new;
>> length Percent 3;
>> retain Amount1;
>> if _N_ = 1 then do;
>> Percent = 100;
>> Amount1 = Amount;
>> end;
>> else do;
>> Percent = (Amount/Amount1) * 100;
>> end;
>> drop Amount1;
>> run;
>>
>> proc print;
>> run;
>>
|