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

Can anyone tell me why I wouldn't keep labels from one dataset to the next?  For example, if running:

 

data work.example1;

   set work.example2;

   (lots of other code in here);

run;

 

Why wouldn't example1 have labels assigned the same as example2?  I'm running a data step like above where new variables are being created and given labels.  The only variables showing up with labels are the new ones being created.

 

Is there an option somewhere that says to "keep" labels based on tables being used to create new ones?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Proc datasets with the modify statement will allow you to set or change labels for an existing data set. If you have the variable names and the label you want in a dataset then you could use call execute.

Or use the set to write a label block of code that you could %include where needed. The only lines needed with the approach would be to save a file named something like: "C:\path\mylabels.sas";

with contents like:

label

   var1 = "Label for the first variable"

   var2 = "Label for the second variable"

;

 

and use:

 

data whatever;

    set anotherdata set;

   %include "C:\path\mylabels.sas";

    <other code>

run;

View solution in original post

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

Are you sure the contributiing dataset has labels?  If so post an example, simple dataset with labels, and your code.  The reason is this:

data tmp;
  set sashelp.cars;
  label abc="A new variable";
  abc="Abcd";
run;

Shows the labels from cars and the one I created no problem.   You sure your not modifying the variables which are coming in anyway?

StaceyB
Obsidian | Level 7

 

I do know the labels are assigned in the contributing table.  I am running a proc contents on the contributing table and see the labels printed in the output.

 

The values of the variables coming in are being changed but nothing else about the variable is changed (ie. length, type). Will I lose the label if ANY change is made to the variable?

StaceyB
Obsidian | Level 7

lf the label is dropped from the contributing table because the value is being changed when creating a new dataset is there a way I can re-assign the labels without having to enter them again?  For example could I create code that utilizes the proc contents output from the contributing table and if the new table doesn't have a label it will check the contributing table for a label and use it if it's there?

 

I think I know the answer to this question, just need to figure out the appropriate macros to use to obtain the data.

 

Thank you.

StaceyB
Obsidian | Level 7

Can I delete this question?

 

I see some macros being used that are renaming the variables.

 

I need to create code that will get the labels from previous and assign them to the new.  (This code is crazy with renaming variables throughout the entire process. This is something I plan to change once I can be sure of which variable is which throughout.

ballardw
Super User

Proc datasets with the modify statement will allow you to set or change labels for an existing data set. If you have the variable names and the label you want in a dataset then you could use call execute.

Or use the set to write a label block of code that you could %include where needed. The only lines needed with the approach would be to save a file named something like: "C:\path\mylabels.sas";

with contents like:

label

   var1 = "Label for the first variable"

   var2 = "Label for the second variable"

;

 

and use:

 

data whatever;

    set anotherdata set;

   %include "C:\path\mylabels.sas";

    <other code>

run;

PoornimaRavishankar
Quartz | Level 8

If you assigned labels using the ATTRIB or the LABEL statements, they should stick.

 

But.

 

If you did this -

 

data one;

attrib var1 label = 'Variable 1';

var1 = 1;

 

data two (keep = var2 rename=(var2=var1));

/* attrib var2 label = 'Variable 2'; */

set one;

var2 = var1;

var3 = var1;

run;

 

proc print data=two; run;

 

No, proc print won't show 'Variable 1' for var1 or var3.

If you uncommented the attrib statement, then the proc print should show the label 'Variable 2' for var1.

 

If you could post some part of the problem code here, we should be able to identify the problem.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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