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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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