SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
emmad511
Fluorite | Level 6

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;
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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";
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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";
PG
Kurt_Bremser
Super User

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;
wilson
Fluorite | Level 6
All classification variables need to be listed in class statement.
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;



ballardw
Super User

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"

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 893 views
  • 5 likes
  • 5 in conversation