BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
akki39k
Calcite | Level 5

I have tow excel files.

First one contain the original data which contains data from a company

The second file contains all the labels for the above data headers

 

My question is that how to label all the headers present in the first file according to the labels present in second file. There are more than 400 header in first file which are needed to properly labeled by the labels present in second file

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Let's make up some data that more or less resembles what you imported from Excel:

Data from the first spreadsheet, with two columns:

data mydata;
input var1 $ var2;
cards;
x 1
y 2
z 3
;
run;

Data from the second spreadsheet, with two lines:

data headers;
infile cards dlm=',';
input col_a $ col_b :$64.;
cards;
var1,this is the label for var1
var2,this is the label for var2
;
run;

Now let's use the second dataset to dynamically create a proc datasets step that sets the labels:

data _null_;
set headers end=eof;
if _n_ = 1 then call execute('proc datasets noprint; modify mydata; label ');
call execute(col_a !! ' = "' !! strip(col_b) !! '" ');
if eof then call execute('; run; quit;');
run;

and print the result:

proc print data=mydata noobs label;
run;

This is what we get:

 this is      this is
the label    the label
for var1      for var2

    x            1    
    y            2    
    z            3    

 

View solution in original post

7 REPLIES 7
akki39k
Calcite | Level 5

I have name label pairs in the second file like

Name of the header in A1 and corresponding label in B2 of spreadsheet

PaigeMiller
Diamond | Level 26

@akki39k wrote:

I have name label pairs in the second file like

Name of the header in A1 and corresponding label in B2 of spreadsheet


Is this a typographical error? Should it say: name of the header in A2 and label in B2?


Can you show us a few records of these label pairs?

--
Paige Miller
Kurt_Bremser
Super User

Let's make up some data that more or less resembles what you imported from Excel:

Data from the first spreadsheet, with two columns:

data mydata;
input var1 $ var2;
cards;
x 1
y 2
z 3
;
run;

Data from the second spreadsheet, with two lines:

data headers;
infile cards dlm=',';
input col_a $ col_b :$64.;
cards;
var1,this is the label for var1
var2,this is the label for var2
;
run;

Now let's use the second dataset to dynamically create a proc datasets step that sets the labels:

data _null_;
set headers end=eof;
if _n_ = 1 then call execute('proc datasets noprint; modify mydata; label ');
call execute(col_a !! ' = "' !! strip(col_b) !! '" ');
if eof then call execute('; run; quit;');
run;

and print the result:

proc print data=mydata noobs label;
run;

This is what we get:

 this is      this is
the label    the label
for var1      for var2

    x            1    
    y            2    
    z            3    

 

akki39k
Calcite | Level 5

My second file looks like this

akki39k
Calcite | Level 5

Thank you for looking into my concern and providing the solution

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1217 views
  • 0 likes
  • 3 in conversation