Hi, Is there any way to use lable name instead of varaible name in data step processing ?
ex:-
Data test;
Name = 'Jon' label first_name;
run;
data test2;
if first_name = 'Jon';
run;
thanks,
No. See VALIDVARNAME=ANY system option if you want to expand the range of valid variable names.
OK. Here is an example.
data class;
set sashelp.class;
label sex='Sex FM' name='NAME' age='P AGE';
keep sex name age;
run;
proc transpose data=class(obs=0) out=temp;
var _all_;
run;
options validvarname=any;
data _null_;
set temp end=last;
if _n_ eq 1 then call execute(catt('proc datasets library=work nolist nodetails;modify class;rename '));
call execute(catt(_name_,'=',nliteral(_label_)));
if last then call execute(';quit;');
run;
What are you trying to do?
Formats control how a variable value's are displayed.
Labels control how a variables name is displayed.
We have to use another team’s DataMart for our processing. We don’t have control on creation of DataMart but we know this DataMart is created by fetching records from Teradata tables. We also use same tables and our most of code is written by using variable name from these tables. Somehow we have to use this DataMart (created by another team) as source for all our code. The problem is team has used alias for most of variables but label is still same as variable name from Teradata tables. Now the only option for us is to use these alias instead of variable name in our code but it’s really tedious to make all the changes.
Is there any way where we can use this DataMart in our code ? We have to use this DataMart so no option to create another DataMart with same name as Teradata tables.
Is there a table anywhere that links the alias to the "full value" you need? It may be possible to link the information in a useful manner. Possibly using Proc Datasets to assign the longer value as labels and rename variables (or vice versa, I'm not quite clear on your requirement).
Or if you have list of your current variables and labels and the datamart variables and labels match those up to create a your variable to their variable list and then use proc datasets to rename your variables.
I've actually done this to include modifying code files to change the variable names.
Provide a bit more explicit example of what is going on, whay you get from the datamart, what you have, what needs to change.
Sorry for not being clear on my requirement.
Here is what is our requirement and what we have.
*** Existing DataMart creation by another team ***;
Proc sql;
Connect Teradata ;
Create table test_Datamart as
Select first_name as fName
Last_name as lname
From custTable
Quit;
Our code:-
Proc sql;
Connect Teradata ;
Create table test as
Select first_name
Last_name
From custTable
Quit;
Data test1;
Set test;
Where first_name = ‘Jon’;
Run;
As per change , we need to use “test_Datamart” in our code instead of “test” data. the problem is “test_Datamart” using alias for all variable name and you can see first_name is fname. So we need to make changes to our code to reflect alias name instead of actual variable name.
This is just one example. In real scenario , there are almost 100 variables in “test_Datamart” and we have almost 25+ codes that now need to change to reflect alias name. I know that label for all these variables in “test_Datamart” is same as actual variable name of tables in Teradata. I just want to know if there is any option to define in any system options or any dataset options so it would take label as variable name in dataset processing.
Like :-
Data test1 label;
Set test_Datamart; *** this dataset renamed first_name to fname but label is still showing first_name.
Where first_name = ‘Jon’; *** I want to use first_name in my code but there is no variable called “first_name “ in test_Datamart.
Run;
Thanks
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.