BookmarkSubscribeRSS Feed
statadm
Fluorite | Level 6
Is there a way to print all of the variables names with the value for one individual record?

For example, I would like to see the following output in two columns:

varname response

ID 2
FNAME JOHN
LNAME DOE
DOB 10/10/1910
PHONE 555-555-5555
ZIP 56879

Thanks in advance for your help!
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
Will you only do this for 1 observation or do you want this format for EVERY observation in a group? What is your destination of interest? (RTF, PDF, HTML)? Are DOB, PHONE and ZIP character or numeric variables? SAS expects an entire column of values to be of the same type (so, for example, if you had a column for SALES, then the value for SALES for EVERY row would be numeric).

In your example, FNAME, LNAME and possibly PHONE might be character, but DOB and ZIP might be numeric -- SAS would "want" the second column to be all character -- which would mean that you would have to convert DOB and ZIP to character variables in order to display them in the same column with FNAME, LNAME and PHONE.

Otherwise, the example is sort of like an example in a previous forum posting:
http://support.sas.com/forums/thread.jspa?messageID=46738뚒 (except in that post, all the variables were character.)

cynthia
statadm
Fluorite | Level 6
So, I only need to do this for one observation. What I really want to do is take a dataset that is in wide format and transpose it to long.

All of the variables are different format types (there are over 3000 variables).

It doesn't matter which destination, anything will work.

If it isn't possible, I guess I can just proc print everything for that one observation.

Thanks!
polingjw
Quartz | Level 8
Could you just use PROC TRANSPOSE with a WHERE statement to identify the one observation? Here is an example.

[pre]
DATA HAVE;
INPUT ID $ FNAME:$12. LNAME:$12. DOB:MMDDYY10. PHONE:$12. ZIP $;
FORMAT DOB MMDDYY10.;
DATALINES;
1 JANE DOE 01/01/2001 999-999-9999 12345
2 JOHN DOE 10/10/1910 555-555-5555 56789
3 JIM DOE 12/12/1912 111-111-1111 34567
;;
RUN;

PROC TRANSPOSE DATA=HAVE OUT=WANT(RENAME=(COL1=VALUE)) NAME=VARIABLE;
VAR _ALL_;
WHERE ID = '2';
RUN;

PROC PRINT DATA=WANT NOOBS;
RUN;
[/pre]
statadm
Fluorite | Level 6
Yes, thank you!
Cynthia_sas
SAS Super FREQ
Hi:
Did you look at this program:
http://support.sas.com/forums/thread.jspa?messageID=46738뚒

It essentially transposes 4 character variables in a DATA step program and then uses PROC REPORT to create the kind of output you want. The only differences in what you would have to do is:
1) you'd subset your data so you'd only have 1 obs of interest and
2) you'd have to use a DATA step and the PUT function to convert all your numeric variables to character and this means that
3) if you had special user-defined formats, you'd have to take those into account

OR
you'd have to run PROC TRANSPOSE -- this will be easier if you do only have ONE observation. See the example below.

cynthia
[pre]
** alternate approach;
proc sort data=sashelp.class
out=onlyone;
where name in ('Alfred');
by name;
run;

** transpose all variables -- usually only numeric are transposed;
** there will be a note in the log about automatic conversion of;
** numeric to character -- if you do not want this automatic conversion,
** (for example, if you have user-defined formats);
proc transpose data=onlyone out=charout;
var _character_ _numeric_;
run;

proc print data=charout;
run;

proc report data=charout nowd;
column _NAME_ COL1;
define _NAME_ / display 'ID';
define COL1 / display 'Value';
run;
[/pre]

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
  • 5 replies
  • 4472 views
  • 0 likes
  • 3 in conversation