Help using Base SAS procedures

Update variable label from different data set

Reply
Super Contributor
Posts: 400

Update variable label from different data set

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.
PROC Star
Posts: 7,468

Re: Update variable label from different data set

Posted in reply to jerry898969
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
Super Contributor
Super Contributor
Posts: 3,174

Re: Update variable label from different data set

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
Super User
Posts: 10,020

Re: Update variable label from different data set

Posted in reply to jerry898969
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
Super Contributor
Posts: 400

Re: Update variable label from different data set

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
Ask a Question
Discussion stats
  • 4 replies
  • 149 views
  • 0 likes
  • 4 in conversation