BookmarkSubscribeRSS Feed
mani0211
Calcite | Level 5

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.

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
mani0211
Calcite | Level 5

 

 

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Astounding
PROC Star

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?

mani0211
Calcite | Level 5

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

Astounding
PROC Star

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 6 replies
  • 1619 views
  • 0 likes
  • 3 in conversation