Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:14:53+00:00 2026-06-08T14:14:53+00:00

I’m looking for a way to create vertical tables in SAS where the variables

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:14:54+00:00Added an answer on June 8, 2026 at 2:14 pm

    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:

    <html>
    <h1> My title is &title </h1><br>
    Name: &name <br>
    Value of Blah: &blah
    </html>
    

    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:

    /*****************************************************************************
    **  PROGRAM: MACRO.RESOLVE_FILE.SAS
    **
    **  READS IN A FILE AND REPLACES ANY MACRO REFERENCES IN THE FILE WITH THE 
    **  ACTUAL MACRO VALUES.  EG.  IF THE FILE WAS AN HTML FILE AND IT CONTAINED 
    **  THE FOLLOWING HTML:
    **
    **    <TITLE>&HTML_TITLE</TITLE>
    **
    **  THEN THE PROGRAM WOULD READ THE FILE IN AND RESOLVE IT SO THAT THE OUTPUT
    **  LOOKED LIKE THIS:
    **
    **    <TITLE>ROB</TITLE>
    **  
    **  ... WHEN THE MACRO VARIABLE "HTML_TITLE" EXISTED AND CONTAINED A VALUE OF 
    **  "ROB".  THIS IS USEFUL WHEN YOU NEED TO CREATE "DYNAMIC" HTML FILES FROM 
    **  SAS BUT DONT WANT TO DO IT FROM A DATASTEP USING PUT STATEMENTS.  DOING
    **  IT THIS WAY IS MUCH CLEANER.
    **
    **  PARAMETERS: NONE
    **
    ******************************************************************************
    **  HISTORY:
    **  1.0 MODIFIED: 22-JUL-2010  BY:RP
    **  - CREATED. 
    **  1.1 MODIFIED: 18-FEB-2011  BY:RP
    **  - ADDED LRECL OF 32K TO STOP TRUNCATION
    *****************************************************************************/
    %macro resolve_file(iFileIn=, iFileOut=);
      data _null_;
        length line $32767;
        infile "&iFileIn" truncover lrecl=32767;
        file   "&iFileOut" lrecl=32767;
        input; 
        line = resolve(_infile_);
        len = length(line);
        put line $varying. len;
      run;
    %mend;
    

    Create some test data. Also create some commands to call the above macro and pass in the values from the dataset:

    data mydata;
      attrib name length=$10 format=$10.    label='FirstName'
             blah length=6   format=comma6. label='SomeValue'
             cmd1  length=$1000
             cmd2  length=$1000
             ;
    
      title = 1; 
      name = "Rob" ; 
      blah = 1000; 
      cmd1 = cats('%let title=',title,';',
                  '%let name=',name,';',
                  '%let blah=',blah,';');
      cmd2 = cats('%resolve_file(iFileIn=c:\template.html, iFileOut=c:\result',title,'.html);');
      output;
    
      title = 2; 
      name = "Pete"; 
      blah = 100 ; 
      cmd1 = cats('%let title=',title,';',
                  '%let name=',name,';',
                  '%let blah=',blah,';');
      cmd2 = cats('%resolve_file(iFileIn=c:\template.html, iFileOut=c:\result',title,'.html);');
      output;
    run;
    

    Use call execute to 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:

    proc sql noprint;      
      select count(*) into :nobs from mydata;
    quit;
    

    Then iterate through the dataset executing the commands one at a time and building each row to a new file:

    %macro publish;
      %local tmp;
      %do tmp = 1 %to &nobs;
        data _null_;
          set mydata(firstobs=&tmp obs=&tmp);
          call execute (cmd1);
          call execute (cmd2);
        run;
      %end;
    %mend;
    %publish;
    

    That should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I would like to count the length of a string with PHP. The string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.