dear all
my dataset is a panel data of nearly 2000 companies for 18 years. for every year, each company observation is repeated for multiple times.
i have to count the frequency of each company for every year in the data set and to prepare a separate frequency table.
the example of my data set is as follows
Company Name | year |
3P Land Holdings Ltd. | 2001 |
3P Land Holdings Ltd. | 2001 |
3P Land Holdings Ltd. | 2001 |
3P Land Holdings Ltd. | 2001 |
3P Land Holdings Ltd. | 2001 |
52 Weeks Entertainment Ltd. | 2001 |
52 Weeks Entertainment Ltd. | 2001 |
52 Weeks Entertainment Ltd. | 2001 |
7Seas Entertainment Ltd. | 2001 |
7Seas Entertainment Ltd. | 2001 |
7Seas Entertainment Ltd. | 2001 |
3P Land Holdings Ltd. | 2002 |
3P Land Holdings Ltd. | 2002 |
3P Land Holdings Ltd. | 2002 |
3P Land Holdings Ltd. | 2002 |
3P Land Holdings Ltd. | 2002 |
3P Land Holdings Ltd. | 2002 |
A B C India Ltd. | 2002 |
A B C India Ltd. | 2002 |
A B C India Ltd. | 2002 |
A B C India Ltd. | 2002 |
A B C India Ltd. | 2002 |
A B C India Ltd. | 2002 |
A B C India Ltd. | 2002 |
the required frequency table is
company name | year | frequency |
3P Land Holdings Ltd. | 2001 | 5 |
52 Weeks Entertainment Ltd. | 2001 | 3 |
A B C India Ltd. | 2002 | 7 |
please suggest me a SAS code to prepare the frequency table as given above.
thanks in advance.
proc freq data=have;
tables Company * Year / list nocum nopct;
run;
Another way:
Proc summary data=have nway; class company year ; output out=work.summary (drop=_type_); run;
The output set work.summary will have a variable named _freq_ with the count of combinations of company and year.
The NWAY is have the output only include records with both company and year. Summary can create a number of other combinations of the class variables. The _type_ variable is an indicator of which combination of class variables each record reflects.
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.