- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello! I have some questions relating to proc tabulate.
For the RealGDP data attached, I would like to use PROC TABULATE to create a table with the state abbreviations (postal) as the rows and the years (Y2012, Y2013, Y2014, Y2015) as the columns, and a table with the state abbreviations (postal) as the rows and the years (Y2012, Y2013, Y2014, Y2015) as the columns with each years’ minimum, mean, and maximum values. Also, for each table, I need a centered blue footnote with a height of 1 called 'Source: Bureau of Economic Analysis'.
Here's what I have for now, but it doesn't print out a table, and I'm not sure where to go from this. For your information, I have already imported the original data into "gdp".
title "Sum of Real GDP by Year";
proc tabulate data=gdp;
by Postal;
table Postal, Y2012*Y2013*Y2014*Y2015;
run;
title;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Start with:
title "Sum of Real GDP by Year";
proc tabulate data=gdp;
var Y2012 Y2013 Y2014 Y2015;
class postal;
table Postal, (Y2012 Y2013 Y2014 Y2015)*(mean min max);
run;
ods text="Source: Bureau of Economic Analysis";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Start with:
title "Sum of Real GDP by Year";
proc tabulate data=gdp;
var Y2012 Y2013 Y2014 Y2015;
class postal;
table Postal, (Y2012 Y2013 Y2014 Y2015)*(mean min max);
run;
ods text="Source: Bureau of Economic Analysis";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Transpose to a long dataset, and let PROC REPORT do the work:
data gdp;
infile
'/folders/myfolders/RealGDP.csv'
dlm=','
dsd
truncover
firstobs=2
;
input postal :$2. y2012-y2015;
run;
data long;
set gdp;
array y {2012:2015} y2012-y2015;
do year = 2012 to 2015;
gdp = y{year};
output;
end;
keep postal year gdp;
run;
proc report data=long;
column postal year,(sum min max),gdp;
define postal / group;
define year / "" across;
define gdp / "" analysis;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
title "Sum of Real GDP by Year";
proc tabulate data=gdp;
Class Postal Y2012 Y2013 Y2014 Y2015;
table Postal, Y2012*Y2013*Y2014*Y2015;
run;
Otherwise if Y2012 to Y2015 are quantitative variables, they need to listed under VAR statement.
proc tabulate data=gdp;
Class Postal;
Var Y2012 Y2013 Y2014 Y2015;
table Postal, (Y2012 Y2013 Y2014 Y2015)*sum='';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Some generic syntax bits in the TABLE statement of Tabulate:
Commas separate dimensions
* nest items
( ) group items.
So if you want the same statistics for multiple variables (var1 var2 var3) * (n mean max <or other valid statistic keywords)
Grouping variables are CLASS variables and must be declared on a Class statement before use.
Variables for statistics like Mean, Max, Sum etc must be declared on a VAR statement before use.
If no specific statistic is requested then you will get N for class variables if there is no interaction (cross or nest) with var variables, and Sum of var variables.
You must have at least one of a Class or Var statement with at least one variable and ALL variables that appear on the Table statement must be defined as class or var to be used. That is why your code generated a bunch of errors about "type of variablename is unknown"