Is it possible to do this with proc freq?
data company;
length co_name $50.;
input co_name $ 1-14 name $ 16-18 totalcontacts;
datalines;
AAA Ford - BMC Dan 8
AAA Ford - BMC Jan 6
AAA Ford - BMC Mar 1
AAA Ford - BMC Tom 5
;
run;
proc freq noprint data=company;
tables name*totalcontacts/out=work.company2;
run;
I want the output to look like this:
AAA Ford - BMC Dan 40%
AAA Ford - BMC Jan 30%
AAA Ford - BMC Mar 5%
AAA Ford - BMC Tom 25%
Thanks
Yes you can do this with proc freq. However proc freq produces a PERCENT variable that generates the number 20 to represent twenty percent, NOT the number 0.2. The problem is that SAS has a percent. format that shows .2 as 20%, but has none to show 20 as 20%.
You can make your own format if you like:
proc format ;
picture pct low-high='009%';
run;
proc freq noprint data=company;
tables co_name*name/out=work.company2 (drop=count);
weight totalcontacts;
format percent pct.;
run;
proc print data=company2;run;
Very easy and straight forward in sql:
data company;
length co_name $50.;
input co_name $ 1-14 name $ 16-18 totalcontacts;
datalines;
AAA Ford - BMC Dan 8
AAA Ford - BMC Jan 6
AAA Ford - BMC Mar 1
AAA Ford - BMC Tom 5
;
run;
proc sql;
create table company2 as
select co_name,name, totalcontacts/sum(totalcontacts) as pct format=percent.
from company
group by co_name;
quit;
I know how to do it in SQL. I thought proc freq might be fewer steps and I'd learn something new. Thanks.
So that's how you do it. Thanks for the help.
Yes you can do this with proc freq. However proc freq produces a PERCENT variable that generates the number 20 to represent twenty percent, NOT the number 0.2. The problem is that SAS has a percent. format that shows .2 as 20%, but has none to show 20 as 20%.
You can make your own format if you like:
proc format ;
picture pct low-high='009%';
run;
proc freq noprint data=company;
tables co_name*name/out=work.company2 (drop=count);
weight totalcontacts;
format percent pct.;
run;
proc print data=company2;run;
Sorry. Replied to wrong post. Thanks for the help.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: