BookmarkSubscribeRSS Feed
nkm123
Calcite | Level 5

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,

 

7 REPLIES 7
PGStats
Opal | Level 21

No. See VALIDVARNAME=ANY system option if you want to expand the range of valid variable names.

PG
Ksharp
Super User
Post some data. and what does your label look like? does it contain some non-word character ? I would do this by proc transpose + proc datasets .
Ksharp
Super User

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;
Reeza
Super User

What are you trying to do? 

 

Formats control how a variable value's are displayed.

Labels control how a variables name is displayed. 

 

 

nkm123
Calcite | Level 5

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.

ballardw
Super User

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.

nkm123
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 7 replies
  • 5809 views
  • 0 likes
  • 5 in conversation