BookmarkSubscribeRSS Feed
jerry898969
Pyrite | Level 9
I have a data set that I want to update the labels too. I have another dataset that lists the variable name and the new label. What is the best way to approach this?

TABLE 1 lets say has 3 variables. (Mine has many more)
var1 var2 var3
The labels for these variables could be 'label1' 'label2' 'label3' .

I want to update these labels based on another dataset

I have another dataset that has
var1 'This is variable 1'
var2 'This is variable 2'
var3 'This is variable 3'

So my final file will have these as the labels not 'label1' 'label2' 'label3' .

Thank you in advance for any help.
4 REPLIES 4
art297
Opal | Level 21
Jerry,

Other than the labels, and number of records, are the two datasets the same (i.e., each with the same number of variables, same variable names and same lengths and formats)?

Art
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With a DATA step approach, you can use VLABEL function to retrieve the assigned variable label and also use the CALL LABEL function to assign the label-value.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic/post:

assign variable label site:sas.com
vlabel function site:sas.com
Ksharp
Super User
Give you an example which I have coded before.
[pre]

%let libname=work;
options compress=yes;


* _col1 is table name _col3 is english variable name _col4 is label;

data _null_;
set work.label(where=(_col1 is not missing)) end=last;
if _n_ eq 1 then call execute("proc datasets library=&libname memtype=data;" );
if _col1 ne lag(_col1) then call execute('modify '||compress(_col1)||';');
call execute('label '||compress(_col3)||'="'||compress(_col4)||'";');
if last then call execute('quit;');
run;
[/pre]

Ksharp
jerry898969
Pyrite | Level 9
Thank for all of your posts. I figured this out by using a macro to cycle through the vars I'm working with. In the macro I generate a sas that has the label statement properly formatted. I created it in a seperate file because of the number of variables I have in some of my tables. I'm dealing with over 5000 variables.
So i have 10 or so files that have label statements. Within my main program I use a macro to create the dataset. Within that macro I have a data step that has the %include as part of it. So all my labels get updated. I think I took the long route but I have to have pretty log files and this way does that.

Thanks again for all of your help

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1278 views
  • 0 likes
  • 4 in conversation