BookmarkSubscribeRSS Feed
hjjijkkl
Pyrite | Level 9

Is it possible to give one variable multiple names using format statement or label statement? 

 

I have a variable called  "clinical" and I want to describe it in 3 different descriptions "visit", "lab" and patient". I am not sure if I will be bale to do it using label statement . 

5 REPLIES 5
mkeintz
PROC Star

You can give a variable only one variable name

 

But you could leverage the syntax of the old-style array declaration, as in:

 

data have;
  set sashelp.class ;
  array a age;
  _i_=1;
  if sex='F' then a=-1*a;
run;

The above effectively aliases the array name a with the variable age.  The resulting dataset will have will not have a variable named a, only the variable age, with values modified as per the code above.  Since this type of SAS array uses the automatic variable _i_ (unsaved in the resulting dataset) as its index, you have to set _i_=1, so that a reference to a accesses the first (and only) member of the array, namely the variable age.  You could make several aliases this way to the same variable, but you only have to set _i_=1 once.

 

In your case, I presume you could use:

 

  array visit clinical;
  array lab clinical;
  array patient clinical;
  _i_=1;

Every reference to the names visit, lab, or patient will use the variable clinical.   I'm not sure I recommend this idea, but it can be done.

 

One major caveat.  If you were to use this technique, do NOT use old style array declarations for any array with multiple elements.  For such cases, use the new style, as in:

  array ret{5} ret1-ret5;

And of course, do not use the variable _I_ for any other purpose.

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

No. 

What are you actually trying to do?

 

You can change the label in the step that is using the dataset.

proc means data=sashelp.class;
  var age;
  label age = 'Age of student';
run;
Kurt_Bremser
Super User

In the physical structure of a dataset, there is one name and one label for each variable, so in the context of stored data, the answer is no.

In the context of data step code, trickery is possible, but it only exists during that particular step, and the confusion caused by such trickery is a VERY BAD THING.

ballardw
Super User

Depending on HOW you are using the variable you can change the LABEL in different procedures or possibly even different uses within a procedure.

 

An example of using a single variable multiple times in Proc Tabulate and changing the LABEL used for each occurrence.

proc tabulate data=sashelp.class;
   class sex age;
   var height weight;
   tables sex='Child sex'*n
          sex='Sex'*height*mean
          sex='Other label'*weight*max,
          age
   ;
run;

But details as to the actual use would be needed to see what other approaches might be useful.

PaigeMiller
Diamond | Level 26

Hello @hjjijkkl 

 

This is such a bad idea, I wonder why you want to do this. You can assign the exact same values to many variables, but even that seems pointless in most cases. And that's not what you asked. You need to re-think this whole thing. Please state your goal behind this question (goal being where you intend to go, not how you want to get there, which is to give variable multiple names).

 

So, I find this such a bad idea, multiple names for one variable, that I repeat the words of @Kurt_Bremser above:

 

In the physical structure of a dataset, there is one name and one label for each variable, so in the context of stored data, the answer is no. In the context of data step code, trickery is possible, but it only exists during that particular step, and the confusion caused by such trickery is a VERY BAD THING.

 

 

--
Paige Miller

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1462 views
  • 2 likes
  • 6 in conversation