I’m looking for a way to create vertical tables in SAS where the variables are each treated as rows (as opposed to each row being an observation).
For example lets say I have some data for a bunch of companies, some of which is more important than others. It is easy to make proc report spit out a summary table with a few variables like this:
Name Price Shares MarketCap
co1 $5 100 $500
co2 $1 100 $100
co3 $2 200 $400
What I want to do after this is print a page of detailed information for each company which is essentially a table with a column for the description and a column for the value (and maybe a third column for the calculation).
Company 1
Location: CA
CEO: Bob Johnson
Industry: Semiconductors
Shares: 100
Share Price: $5
Market Cap: $500
The only way I can think of to do this in SAS is to basically transpose everything, create a new character variable that has the label (Location, Stock Price, Etc) and a second character variable that has the value and then make a two column report BY company to get a page for each. This is messy since some of the values are numeric and others are character so to get them to display on one column requires creating a new character variable and filling it with text versions of the numeric variables.
I figure there has got to be an easier way to create a vertical table since there are so many easy ways to create the horizontal tables.
There is also this solution which is probably better for your needs.
First create a HTML file that will be used as a template. Wherever you want to put a value, use a macro variable as a placeholder like so:
Make it as attractive looking as you like.
Next create a macro that will import the HTML template, replace the placeholders with actual values and save the result to a new file:
Create some test data. Also create some commands to call the above macro and pass in the values from the dataset:
Use
call executeto run the cmd1 and cmd2 that we created in the prior dataset. We have to only execute call execute on 1 row at a time so that the correct macro variables are used so do it using a loop. First calculate the number of rows in your dataset using your preferred technique:Then iterate through the dataset executing the commands one at a time and building each row to a new file:
That should do the trick.