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 .
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.
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;
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.
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.
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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.