BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cs
Calcite | Level 5 cs
Calcite | Level 5

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

Accepted Solutions
shivas
Pyrite | Level 9

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

15 REPLIES 15
art297
Opal | Level 21

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.

cs
Calcite | Level 5 cs
Calcite | Level 5

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.  

shivas
Pyrite | Level 9

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

art297
Opal | Level 21

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;

ballardw
Super User

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.

art297
Opal | Level 21

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.

Tom
Super User Tom
Super User

proc fsbrowse data=SASHELP.CLASS label printall ;

run;

Howles
Quartz | Level 8

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.

art297
Opal | Level 21

: 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

Cynthia_sas
SAS Super FREQ

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

Reeza
Super User

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;

art297
Opal | Level 21

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

Cynthia_sas
SAS Super FREQ

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

art297
Opal | Level 21

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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