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
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
How do they correspond to each other? By position in the spreadsheet only, or do you have name/label pairs?
I have name label pairs in the second file like
Name of the header in A1 and corresponding label in B2 of spreadsheet
@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?
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
My second file looks like this
So you just have to use variable in place of col_a and label in place of col_b.
Thank you for looking into my concern and providing the solution
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.