Help using Base SAS procedures

Variable Labels

Reply
Occasional Contributor
Posts: 7

Variable Labels

Hi,

 

I have a SAS file A which has no labels. I have another file B in which i have only 2 columns which has values (Column1: All column names in Table 1 and Column2 has all the labels) How to pull the labels which are present as a values from File B and make it as a label in File A.

Super User
Super User
Posts: 7,942

Re: Variable Labels

Hi,

 

Something like:

data main;
  a=1234;
  b=23;
run;

data labels;
  var="a"; lab="A label for a"; output;
  var="b"; lab="A label for b"; output;
run;

data _null_;
  set labels end=last;
  if _n_=1 then call execute('proc datasets nolist lib=work; modify main; label ');
  call execute(cat(var,'="',strip(lab),'" '));
  if last then call execute(';quit;');
run;
Occasional Contributor
Posts: 7

Re: Variable Labels

 

 

Dataset1

 

NameAgeSexSalary
Mani22M10000
santhosh23M12000
karan24M13000
vijay25M14000
    
 Dataset 2   
collabel  
NameName of the employee
Ageage of the employee
Sexsex of the employee
Salarysalary of the employee

 

Does it work in the above scenario? i wanna create a Dataset3 which is a copy of dataset 1 with all the labels

Super User
Super User
Posts: 7,942

Re: Variable Labels

Yes, your data looks exactly like the test data I provided above.

Super User
Posts: 5,500

Re: Variable Labels

Actually, this program does not create Dataset3.  Instead, it modifies Dataset1 by adding the labels to it.

 

Is there any reason you would need two data sets that are identical, except for the labels?

Occasional Contributor
Posts: 7

Re: Variable Labels

Posted in reply to Astounding

can you alter this and tell me how to create a 3rd dataset and migrate dataset 1 and labels from dataset 2 to the new dataset?

 

Dataset Name 1:AE

Dataset Name 2: AE_INFO

Dataset Name 3: Test_AE

 

Colums in AE_INFO= name and label

Super User
Posts: 5,500

Re: Variable Labels

Very similar tools ... the idea is to generate the proper DATA step:

 

data _null_;

call execute('data test_ae; set ae; label ');

do until (done);

   set ae_info end=done;

   call execute(col || '= "' || label || '"');

end;

call execute('; run;');

stop;

run;

Ask a Question
Discussion stats
  • 6 replies
  • 451 views
  • 0 likes
  • 3 in conversation