Deart experts,
the data set I have:
Company_A | year | Deal.Type |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2016 | Partnership |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2016 | VentureFinancing |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2016 | VentureFinancing |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2017 | Partnership |
(R) DENTAL | 2004 | Acquisition |
0811769 BC ULC | 2010 | Acquisition |
0902337 BC | 2011 | Acquisition |
1 MEDICAL DISTRIBUTION INC ASSETS | 2011 | Acquisition |
10 P S | 2007 | Acquisition |
1077801 BC | 2016 | Acquisition |
10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) | 2011 | Acquisition |
10X FUND LP | 2009 | PrivateEquity |
10X FUND LP | 2009 | PrivateEquity |
10X FUND LP | 2009 | PrivateEquity |
10X FUND LP | 2009 | PrivateEquity |
10X FUND LP | 2009 | PrivateEquity |
10X FUND LP | 2009 | PrivateEquity |
10X FUND LP | 2010 | PrivateEquity |
10X FUND LP | 2010 | PrivateEquity |
10X FUND LP | 2016 | PrivateEquity |
10X GENOMICS | 2015 | Partnership |
10X GENOMICS | 2015 | Partnership |
10X GENOMICS | 2015 | VentureFinancing |
10X GENOMICS | 2015 | VentureFinancing |
10X GENOMICS | 2015 | VentureFinancing |
10X GENOMICS | 2015 | VentureFinancing |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | Partnership |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
10X GENOMICS | 2016 | VentureFinancing |
wanted data set is a brief over view, may would look like the pivot table in excel:
adding one colum that has total number of records grouped by company, year, deal.type
Company_A | year | Deal.Type | yearly_type_sum |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2016 | Partnership | 1 |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2016 | VentureFinancing | 2 |
(PERTHERA) PERSONALIZED CANCER THERAPY | 2017 | Partnership | 1 |
(R) DENTAL | 2004 | Acquisition | 1 |
0811769 BC ULC | 2010 | Acquisition | 1 |
0902337 BC | 2011 | Acquisition | 1 |
1 MEDICAL DISTRIBUTION INC ASSETS | 2011 | Acquisition | 1 |
1077801 BC | 2016 | Acquisition | 1 |
10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) | 2011 | Acquisition | 1 |
10X FUND LP | 2009 | PrivateEquity | 6 |
10X FUND LP | 2010 | PrivateEquity | 2 |
10X FUND LP | 2016 | PrivateEquity | 1 |
10X GENOMICS | 2015 | Partnership | 1 |
10X GENOMICS | 2015 | VentureFinancing | 3 |
10X GENOMICS | 2016 | Partnership | 5 |
tried to achieve this using proc sql, but having difficulties.
It looks like you're trying to count/attach counts.
If you want counts overall, SQL is pretty good. If you want row numbers its not as good.
If you want a 'counter' variable:
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
proc sql;
create table want_SQL as
select company_a, year, dealType, count(*) as num_records
from have
group by company_a, year, dealType;
quit;
PROC FREQ is more efficient though - it'll be faster and has other output options that can be helpful, such as percents of overall, row/column to get statistics more quickly.
proc freq data=have;
table company_a*year*dealType / out = WANT_FREQ;
run;
@jimmychoi wrote:
Deart experts,
the data set I have:
Company_A year Deal.Type (PERTHERA) PERSONALIZED CANCER THERAPY 2016 Partnership (PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing (PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing (PERTHERA) PERSONALIZED CANCER THERAPY 2017 Partnership (R) DENTAL 2004 Acquisition 0811769 BC ULC 2010 Acquisition 0902337 BC 2011 Acquisition 1 MEDICAL DISTRIBUTION INC ASSETS 2011 Acquisition 10 P S 2007 Acquisition 1077801 BC 2016 Acquisition 10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) 2011 Acquisition 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2010 PrivateEquity 10X FUND LP 2010 PrivateEquity 10X FUND LP 2016 PrivateEquity 10X GENOMICS 2015 Partnership 10X GENOMICS 2015 Partnership 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing
wanted data set is a brief over view, may would look like the pivot table in excel:
adding one colum that has total number of records grouped by company, year, deal.type
Company_A year Deal.Type yearly_type_sum (PERTHERA) PERSONALIZED CANCER THERAPY 2016 Partnership 1 (PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing 2 (PERTHERA) PERSONALIZED CANCER THERAPY 2017 Partnership 1 (R) DENTAL 2004 Acquisition 1 0811769 BC ULC 2010 Acquisition 1 0902337 BC 2011 Acquisition 1 1 MEDICAL DISTRIBUTION INC ASSETS 2011 Acquisition 1 1077801 BC 2016 Acquisition 1 10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) 2011 Acquisition 1 10X FUND LP 2009 PrivateEquity 6 10X FUND LP 2010 PrivateEquity 2 10X FUND LP 2016 PrivateEquity 1 10X GENOMICS 2015 Partnership 1 10X GENOMICS 2015 VentureFinancing 3 10X GENOMICS 2016 Partnership 5
tried to achieve this using proc sql, but having difficulties.
There are some suggestions here that might help:
https://communities.sas.com/t5/SAS-Procedures/changing-columns-into-rows/td-p/27547
This is exactly what PROC FREQ does.
proc freq data=have noprint;
tables company_a*year*deal_type/list out=want(drop=percent);
run;
It looks like you're trying to count/attach counts.
If you want counts overall, SQL is pretty good. If you want row numbers its not as good.
If you want a 'counter' variable:
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
proc sql;
create table want_SQL as
select company_a, year, dealType, count(*) as num_records
from have
group by company_a, year, dealType;
quit;
PROC FREQ is more efficient though - it'll be faster and has other output options that can be helpful, such as percents of overall, row/column to get statistics more quickly.
proc freq data=have;
table company_a*year*dealType / out = WANT_FREQ;
run;
@jimmychoi wrote:
Deart experts,
the data set I have:
Company_A year Deal.Type (PERTHERA) PERSONALIZED CANCER THERAPY 2016 Partnership (PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing (PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing (PERTHERA) PERSONALIZED CANCER THERAPY 2017 Partnership (R) DENTAL 2004 Acquisition 0811769 BC ULC 2010 Acquisition 0902337 BC 2011 Acquisition 1 MEDICAL DISTRIBUTION INC ASSETS 2011 Acquisition 10 P S 2007 Acquisition 1077801 BC 2016 Acquisition 10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) 2011 Acquisition 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2009 PrivateEquity 10X FUND LP 2010 PrivateEquity 10X FUND LP 2010 PrivateEquity 10X FUND LP 2016 PrivateEquity 10X GENOMICS 2015 Partnership 10X GENOMICS 2015 Partnership 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2015 VentureFinancing 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 Partnership 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing 10X GENOMICS 2016 VentureFinancing
wanted data set is a brief over view, may would look like the pivot table in excel:
adding one colum that has total number of records grouped by company, year, deal.type
Company_A year Deal.Type yearly_type_sum (PERTHERA) PERSONALIZED CANCER THERAPY 2016 Partnership 1 (PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing 2 (PERTHERA) PERSONALIZED CANCER THERAPY 2017 Partnership 1 (R) DENTAL 2004 Acquisition 1 0811769 BC ULC 2010 Acquisition 1 0902337 BC 2011 Acquisition 1 1 MEDICAL DISTRIBUTION INC ASSETS 2011 Acquisition 1 1077801 BC 2016 Acquisition 1 10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) 2011 Acquisition 1 10X FUND LP 2009 PrivateEquity 6 10X FUND LP 2010 PrivateEquity 2 10X FUND LP 2016 PrivateEquity 1 10X GENOMICS 2015 Partnership 1 10X GENOMICS 2015 VentureFinancing 3 10X GENOMICS 2016 Partnership 5
tried to achieve this using proc sql, but having difficulties.
data have;
input Company_A & $100. year DealType :$100.;
cards;
(PERTHERA) PERSONALIZED CANCER THERAPY 2016 Partnership
(PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing
(PERTHERA) PERSONALIZED CANCER THERAPY 2016 VentureFinancing
(PERTHERA) PERSONALIZED CANCER THERAPY 2017 Partnership
(R) DENTAL 2004 Acquisition
0811769 BC ULC 2010 Acquisition
0902337 BC 2011 Acquisition
1 MEDICAL DISTRIBUTION INC ASSETS 2011 Acquisition
10 P S 2007 Acquisition
1077801 BC 2016 Acquisition
10TH RAMADAN FOR PHARMACEUTICALS AND DIAGNOSING PRODUCTS (RAMIDA) 2011 Acquisition
10X FUND LP 2009 PrivateEquity
10X FUND LP 2009 PrivateEquity
10X FUND LP 2009 PrivateEquity
10X FUND LP 2009 PrivateEquity
10X FUND LP 2009 PrivateEquity
10X FUND LP 2009 PrivateEquity
10X FUND LP 2010 PrivateEquity
10X FUND LP 2010 PrivateEquity
10X FUND LP 2016 PrivateEquity
10X GENOMICS 2015 Partnership
10X GENOMICS 2015 Partnership
10X GENOMICS 2015 VentureFinancing
10X GENOMICS 2015 VentureFinancing
10X GENOMICS 2015 VentureFinancing
10X GENOMICS 2015 VentureFinancing
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 Partnership
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
10X GENOMICS 2016 VentureFinancing
;
proc summary data=have nway;
class Company_A year DealType;
output out=want(drop=_type_ rename=(_freq_=yearly_type_sum)) ;
run;
data _null_ ;
if _n_=1 then do;
dcl hash H (ordered:'a') ;
h.definekey ("Company_A", "year" ,"DealType") ;
h.definedata ("Company_A", "year" ,"DealType","yearly_type_sum") ;
h.definedone () ;
end;
set have end=z;
if h.find() ne 0 then yearly_type_sum=1;
else yearly_type_sum=sum(yearly_type_sum,1);
h.replace();
if z;
h.output(dataset:'want');
run;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.