DATA Step, Macro, Functions and more

descriptive statistics

Accepted Solution Solved
Reply
Contributor
Posts: 72
Accepted Solution

descriptive statistics

I want to make following table. excel file is attached with this . fam is 0 for non-family firms while fam is 0 for family firms. 

Country JPN
                                         Book deb ratio
                               N    mean   median  max  min
 Family firms
Non-family firms
 
Country Kor                         Book deb ratio
                               N    mean   median  max  min
 Family firms
Non-family firms
 

Accepted Solutions
Solution
‎06-16-2016 08:17 AM
Super User
Posts: 7,863

Re: descriptive statistics

Posted in reply to Jahanzaib

Then sort by country before the summary/means:

proc sort data=temp;
by country;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 7,863

Re: descriptive statistics

Posted in reply to Jahanzaib

Try this:

(added my own datastep, as I never open Office files from the web)

data have;
input country $ fam bdr;
cards;
JPN 0 5
JPN 0 6
JPN 1 3
JPN 1 4
KOR 0 3
KOR 0 2
KOR 1 4
KOR 1 5
;
run;

proc summary data=have;
var bdr;
class fam;
by country;
output
  out=want (
    drop=_type_
    rename=(_freq_=N)
    where=(fam ne .)
  )
  mean(bdr)=mean
  median(bdr)=median
  max(bdr)=max
  min(bdr)=min
;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 72

Re: descriptive statistics

Posted in reply to KurtBremser

Thanks for your reply but it do not explain the things that i want. because it only work for the mentioned countries and inclue only 5 observations. anyone here who can open my excel file and explain in more detail?

Super User
Posts: 7,863

Re: descriptive statistics

Posted in reply to Jahanzaib

Post your data in a more sensible and less dangerous format (.csv, for instance).

Or import your excel data into SAS and then create a sample dataset, as described in

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: descriptive statistics

Posted in reply to Jahanzaib

Maybe this...?

 

Proc sort data=your.data;

by country;

run;

 

proc means data=your.data  n mean median max min;

var ...;

class fam;

by country;

run;

Super User
Posts: 10,045

Re: descriptive statistics

Posted in reply to Jahanzaib

It is easy for proc tabulate.

 

proc import datafile='/folders/myfolders/22.xls' out=have replace dbms=xls;run;
data temp;
 set have;
 length F $ 20;
 if Fam=0 then F='Non-family firms';
  else if Fam=1 then F='Family firms';
run;
options nobyline;
title j=l "Country #byval1";
proc tabulate data=temp;
by count;
var book_debt_ratio;
class F;
table F=' ',book_debt_ratio*(N    mean   median  max  min);
run;
Contributor
Posts: 72

Re: descriptive statistics

when i put the complete data which contain 9 countries than it comes up with this error. 

 

ERROR: Data set WORK.TEMP is not sorted in ascending sequence. The current BY group has Count =
JPN and the next BY group has Count = HKG.

Solution
‎06-16-2016 08:17 AM
Super User
Posts: 7,863

Re: descriptive statistics

Posted in reply to Jahanzaib

Then sort by country before the summary/means:

proc sort data=temp;
by country;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 72

Re: descriptive statistics

Posted in reply to KurtBremser

I want to merge two data's. in both excel files the company name are same i have data for 14 years so i want to merge two files in a sense that company name and data for a particular year apear togather.  for example i have stock data for 100 companies for 14 years is in one file and total assets data for those 100 companies for 14 years is another file. how can i merge these two files.  both the files contain same companies names and same years. Thanks in anticipation.

New Contributor
Posts: 3

Re: descriptive statistics

Posted in reply to Jahanzaib

Before any using of BY statement, the data set has to be sorted:

Proc sort data=your.data;

by country;

run;

Contributor
Posts: 72

Re: descriptive statistics

I have got my results in the form 10.02 i want to get the results upto 4 points. can you describe how can i take this upto four point like 10.02 to 10.0214

Super User
Posts: 7,863

Re: descriptive statistics

Posted in reply to Jahanzaib

Add a format to the variable, like this:

proc summary data=have;
var bdr;
class fam;
by country;
attrib bdr format=10.4;
output
  out=want (
    drop=_type_
    rename=(_freq_=N)
    where=(fam ne .)
  )
  mean(bdr)=mean
  median(bdr)=median
  max(bdr)=max
  min(bdr)=min
;
run;

The format will be inherited by the statistics.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 709 views
  • 1 like
  • 4 in conversation