BookmarkSubscribeRSS Feed
A_Kh
Lapis Lazuli | Level 10

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!

 

8 REPLIES 8
japelin
Rhodochrosite | Level 12

like this?

2021-09-02_00h31_25.png

 

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.)

A_Kh
Lapis Lazuli | Level 10

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. 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
FreelanceReinh
Jade | Level 19

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:

vert_labels.png

 

Edit: Added comments to the SAS code.

mkeintz
PROC Star

@FreelanceReinh 

 

Very nice.   The ability to support vertical display of var names might be a worthy request for SAS developers.     

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

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?

A_Kh
Lapis Lazuli | Level 10
No, it's about dataset. I'm not using any tool, its regular viewer window
inside the SAS.
FreelanceReinh
Jade | Level 19

Here is a variant of my previous suggestion

  • using SASHELP.VCOLUMN instead of a dataset VARLIST created in a separate step
  • using CALL EXECUTE, thus obviating the need for a temporary code file
  • allowing for non-standard variable names
  • inserting only '0A'x (instead of '0D0A'x) between the letters of the variable name in the label, as this is sufficient to obtain the vertical display in SAS Universal Viewer ('0D'x works as well).
/* 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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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
  • 8 replies
  • 1107 views
  • 4 likes
  • 6 in conversation