Hi all,
Does anybody know if there is any technique to change variable name from horizontal to vertical? It should be in sas dataset, not in proc step outputs (as I know in proc print it is possible).
Ex:
I have SUBJID AGE GENDER
Want S A G
U G E
B E N
J D
I E
D R
Many thanks, in advance!
like this?
As far as I know there is no way to do this, but please let me know why you want to do it that way. I'm interested.
(The image above is just a variable label with a space in it.)
Hi @japelin ,
Thank you for your feedback. There is a big dataset with more than 200 variables, with long variable names but with only single digits as a value. Having vertical variable name could make it shorter and easier to read.
No such thing if you are referring to SAS data sets.
If you are trying to create an output, then PROC PRINT will do this.
Hi @A_Kh,
Good idea from @japelin to use labels instead of variable names. So you could create a copy of the dataset in question with "vertical" labels (or just add those labels to the existing dataset if it doesn't have variable labels yet). Then use the SAS Universal Viewer rather than the Viewtable window to view the dataset (and switch to "Display Labels" in the View menu or the context menu of a column header, see screenshot below).
Example:
/* Create sample data for demonstration */
data have;
input SUBJID $ AGE GENDER $;
cards;
001 42 F
;
/* Create list of variable names */
proc transpose data=have(obs=0) out=varlist;
var _all_;
run;
/* Write PROC DATASETS code to a temporary file */
filename lblcode temp;
data _null_;
file lblcode;
set varlist end=last;
if _n_=1 then do;
put 'proc datasets lib=work nolist; modify have;';
put 'label';
end;
put _name_ '= "' @;
w=length(_name_);
do i=1 to w;
c=char(_name_,i);
put c $hex2. @;
if i<w then put '0D0A' @;
end;
put '"x';
if last then put '; quit;';
run;
/* Add the variable names as "vertical" labels to dataset WORK.HAVE */
%inc lblcode;
Result:
Edit: Added comments to the SAS code.
Very nice. The ability to support vertical display of var names might be a worthy request for SAS developers.
Datasets do not have name in either horizontal or vertical orientation.
You must be talking about some TOOL you are using the VIEW the dataset.
What tool are you using?
Here is a variant of my previous suggestion
/* Create a new sample dataset */
options validvarname=any;
data have2;
input SUBJID $ AGE GENDER $ 'this is a 32-char. variable name'n;
cards;
001 42 F 9
;
/* Add the variable names as "vertical" labels */
%let ds=work.have2;
data _null_;
length ren $165;
set sashelp.vcolumn(where=(libname="%upcase(%scan(&ds,1,.))"
& memname="%upcase(%scan(&ds,2,.))")) end=last;
if _n_=1 then call execute("proc datasets lib=%scan(&ds,1,.) nolist; modify %scan(&ds,2,.); label");
ren=cats(nliteral(name),'="');
w=length(name);
do i=1 to w;
ren=catt(ren,put(char(name,i),$hex2.));
if i<w then ren=catt(ren,'0A');
end;
ren=catt(ren,'"x');
call execute(ren);
if last then call execute('; quit;');
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.