Hi any SAS expert,
I am a new SAS learner. Right now I am replicating a paper for my summer project. Could anybody help me out with counting the firms that did not pay dividend (denote by variable :Nonpayers = 0) by ticker in SAS? It would be greatly appreciated. Here is the file of my codes attached. Thank you!
You need to describe the actual data you need summarized a bit more clearly, or better yet provide an example. Best is a data step code block to provide something we can test code against.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
The questions that come up are things like is the ticker ever duplicated? And do you need a data set, for manipulation, or a report for people to read.
A simple report could be if ticker is not duplicated and you actually want to count the records where nonpayers=0.
proc tabulate data=have; where nonpayers=0; tables all,n; run;
If more is needed then descriptions, and as I mentioned above, data are needed.
Hi ballardw,
Thank you so much. I am replicating Table 1 in a paper. I need to find the median of the number of firms that do not pay dividends. But I do not know how to use SAS to write the codes for this. The output I wrote the codes for the the median of the number of firms that do not pay dividends is way too bigger than the median value in the paper. For example, in the paper, the authors state:
Nonpayers:
Number of firms: 3,015 (in the paper)
while the result from me:
Nonpayers:
Number of firms: 84,691
So, I know that I wrote the wrong codes. But I really don't know how to figure it out. Here is the code file attached. Please help me out. I will really appreciate it.
@jlkasper1231 wrote:
Hi ballardw,
Thank you so much. I am replicating Table 1 in a paper. I need to find the median of the number of firms that do not pay dividends. But I do not know how to use SAS to write the codes for this. The output I wrote the codes for the the median of the number of firms that do not pay dividends is way too bigger than the median value in the paper. For example, in the paper, the authors state:
Nonpayers:
Number of firms: 3,015 (in the paper)
while the result from me:
Nonpayers:
Number of firms: 84,691
So, I know that I wrote the wrong codes. But I really don't know how to figure it out. Here is the code file attached. Please help me out. I will really appreciate it.
Median implies the middle of something. So you are missing at least one element as to how the tickers are considered to get a "median". Such as "Median number per year" where you have multiple years of data with year1, year2, year3 etc count of companies as non-payers. Then take the median of those annual values.
How to count something really does depend on the way data is structured. And we have no idea what your data looks like. Unfortunately most code is useless without the accompanying data.
Personally in many "counting" situations I will code a variable as 1 with the property of interest and 0 otherwise. Then I can use procedures like Proc Means to SUM that indicator variable to give me a count of things I want.
Here is an example with fake data. This would set approximately 20 percent of tickers in each year to not pay a dividend. The first data set would represent the "raw data" of one record per ticker per year. The proc summary step counts (sums) the number of 1's set in the first set. The Proc means reports on the median value. Other report procedures such as Proc Report or Proc tabulate could be used to generate a table as well. Or Proc Means/Summary could generate a data set with the value and Proc Print display the value.
data example; do ticker = 1 to 75; do year = 1950 to 2000; /* the following line simulates whether a particular "ticker" paid a dividend in a given year. 1=NO dividend */ nodividend = (rand('uniform') > .8); output; end; end; run; /* count of non divend per year across the tickers*/ proc summary data=example nway; class year; var nodividend; output out=counts( drop=_:) sum=; run; proc means data=counts median; title "Median no dividend 1950 to 2000"; var nodividend; run;title;
Hi ballardw,
Wow, thank you so much for your informative example. It is is very helpful. I really appreciate it.
Best regards,
Junli
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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: