I have the below dataset
data A;
Input CHANNEL $ AMOUNT ;
cards;
ABC 110
ABC 220
ABC 770
BBC 810
BBC 190
;
run;
May I know how to generate the below output with the above data? Thanks.
Channel Amount Percent
Proc means/summary/freq. Simple search on the SAS docs gives examples:
Hi scb,
As RW9 already stated in his post see the example link he provided.
But hereby a little bit of code to get you started:
Data A;
Input Channel $ Amount ;
cards;
ABC 110
ABC 220
ABC 770
BBC 810
BBC 190
;
run;
Proc SQL;
Create Table B AS
Select *,(Amount/SUM(Amount)) AS Percent format=6.2
From A
Group BY Channel;
Quit;
data A;
Input CHANNEL $ AMOUNT ;
cards;
ABC 110
ABC 220
ABC 770
BBC 810
BBC 190
;
run;
proc sql;
select *,AMOUNT/sum(AMOUNT) format=percent8.2
from a as x
group by CHANNEL;
quit;
data A;
Input CHANNEL $ AMOUNT ;
cards;
ABC 110
ABC 220
ABC 770
BBC 810
BBC 190
;
run;
DATA A2;
SET A;
CHAR_AMOUNT=AMOUNT;
RUN;
PROC FORMAT;
PICTURE PCTPIC low-high='000.0%';
RUN;
TITLE;
PROC TABULATE DATA=WORK.A2 OUT=TEST ;
CLASS CHANNEL CHAR_AMOUNT;
KEYLABEL PCTSUM="% within Channel";
VAR amount;
TABLE CHANNEL*CHAR_AMOUNT, (amount*(SUM*F=6. PCTSUM<AMOUNT*CHAR_AMOUNT>*F=PCTPIC.)) / RTS=20;
RUN;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.