Help using Base SAS procedures

Displaying data by column, not row

Accepted Solution Solved
Reply
New Contributor cs
New Contributor
Posts: 3
Accepted Solution

Displaying data by column, not row

Hi, I'd like to create a table like the following where the variable names/labels are in the first column and associated values are in the second column but I am having a hard time finding coding for this online or in the SAS guides. Any suggestions would be appeciated.

           

NameIndiviual A's Name
St AddressIndiviual A's St Address
CityIndiviual A's City
StateIndiviual A's State
Zip CodeIndiviual A's Zip Code
Phone NumberIndiviual A's Phone Number
EmailIndiviual A's Email

Accepted Solutions
Solution
‎11-02-2012 04:13 PM
Super Contributor
Posts: 349

Re: Displaying data by column, not row

Hi,

How about Proc transpose..

data have;

input name $ add $  city $  country $;

cards;

shiva ramnagar delhi india

;

run;

proc transpose data=have out=want;

VAR name add city country;

run;

Thanks,

Shiva

View solution in original post


All Replies
PROC Star
Posts: 7,492

Re: Displaying data by column, not row

If you open a SAS dataset by double clicking on it in the SAS explorer window that will bring up the table using the viewtable program.  Once it is open, if you click on view (from the menu bar) you can switch the view from table view to form view.

That may be what you are looking for.

New Contributor cs
New Contributor
Posts: 3

Re: Displaying data by column, not row

Thanks, that's helpful but I need it as output to include in a report. I tried looking at options in proc print but didn't see anything that would display the data like the table above.  

Solution
‎11-02-2012 04:13 PM
Super Contributor
Posts: 349

Re: Displaying data by column, not row

Hi,

How about Proc transpose..

data have;

input name $ add $  city $  country $;

cards;

shiva ramnagar delhi india

;

run;

proc transpose data=have out=want;

VAR name add city country;

run;

Thanks,

Shiva

PROC Star
Posts: 7,492

Re: Displaying data by column, not row

Here is one possibility:

proc sql noprint;

  select catx(" ","variable='",name,"';value=",name,";output;")

    into :vars separated by " "

      from dictionary.columns

        where libname="SASHELP" and

          memname="CLASS"

  ;

quit;

data want (keep=variable value);

  length variable $32;

  length value $32;

  set sashelp.class;

  &vars.;

run;

proc print data=want;

run;

Super User
Posts: 11,343

Re: Displaying data by column, not row

Is that data example in a SAS data set? If so, please run proc contents on the data set and show the results.

If it is not in a SAS data set then the question is how to read the file and that can depend on a whole lot of factors such as file type.

PROC Star
Posts: 7,492

Re: Displaying data by column, not row

One more thought in case the other suggestions don't meet your needs.  Take a look at:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002153702.htm

I wasn't even aware of it before you asked your question, but found it via a Google search.

Super User
Super User
Posts: 7,083

Re: Displaying data by column, not row

proc fsbrowse data=SASHELP.CLASS label printall ;

run;

Regular Contributor
Posts: 184

Re: Displaying data by column, not row

There used to be a PROC LABEL (or maybe it was PROC LABELS) intended for printing adhesive labels but also suitable for a task like this. I can't find it now.

PROC Star
Posts: 7,492

Re: Displaying data by column, not row

: I 'm not aware of such a proc and can't find anything on it.  Did you possibly mean proc forms?

see, e.g.: http://support.sas.com/kb/25/335.html

SAS Super FREQ
Posts: 8,869

Re: Displaying data by column, not row

I agree with Art, I was remembering PROC FORMS. It will probably only work with LISTING, though. As I remember, you used it to do mailing labels and mounted the forms onto the printer. I think you could tell it how many pages of XXX's to print so the operators could align the label sheets.

Oh, my! What a blast from the past! Computer rooms, operators, line printers & pinfeed forms!

cynthia

Super User
Posts: 19,878

Re: Displaying data by column, not row

Are you looking for something like the following?

What's your output destination?

DATA NULL;

FILE 'z:\DROPBOX\TEMP.TXT';

SET SASHELP.CLASS;

PUT "Name: " NAME;

PUT "AGE: " AGE;

PUT "WEIGHT: " WEIGHT;

RUN;

PROC Star
Posts: 7,492

Re: Displaying data by column, not row

One more possibility to add to the list .. one which I'm surprised that didn't suggest: proc report.

The following paper gives step-by-step examples for using both proc forms and proc report:

http://www2.sas.com/proceedings/sugi31/149-31.pdf

SAS Super FREQ
Posts: 8,869

Re: Displaying data by column, not row

Art:

  I was just so caught up in nostalgia for the old days of pinfeed label forms, I did neglect to mention PROC REPORT. But actually, if the need is NOT for Avery labels, but just for listing the variables in one or two columns -- since PROC REPORT needs a DATA step to manipulate the data, I'd probably just use FILE PRINT ODS within the DATA step program. Not sure whether I'd make a table template or not. But probably not.

  Before I went down any of those roads -- PROC FORMS or DATA _NULL_ or PROC REPORT, I would be tempted to make a form in Word with merge fields defined, then I would make a simple CSV file with SAS and do the merge of the CSV file with the Word doc from within Word.

  Of course, I'm still blissing out over PROC FORMS memories. That is a good paper, thanks for providing the link.

cynthia

PROC Star
Posts: 7,492

Re: Displaying data by column, not row

Posted in reply to Cynthia_sas

Cynthia: Enjoy the memories.  I'll try to bring up some new(old) ones next week so that the nostalgic period can continue.  Hmmm .. proc explode, proc spell, proc hier, proc gwhiz, proc nickname, proc extract, proc kba and proc fscalc might be good candidates

🔒 This topic is solved and locked.

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

Discussion stats
  • 15 replies
  • 395 views
  • 0 likes
  • 8 in conversation