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

Hi, 

I am trying to set datasets with same names that have different labels. The names are not what I am interested in. I want to keep the labels. Do you have any idea how I can do this?

e.g.

Dataset1

name = city1, label=city_name_very_too_long_to_be_a_nameBoston

name = city2, label=city_name_very_too_long_to_be_a_nameNewYork

 

Dataset2

name = city1, label=city_name_very_too_long_to_be_a_nameChicago

name = city2, label=city_name_very_too_long_to_be_a_nameCapeCod

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@Roger5 wrote:

Hi,

Dataset1

name = city1, label=city_name_very_too_long_to_be_a_nameBoston, n=20

name = city2, label=city_name_very_too_long_to_be_a_nameNewYork, n=10

 

Dataset2

name = city1, label=city_name_very_too_long_to_be_a_nameChicago, n=5

name = city2, label=city_name_very_too_long_to_be_a_nameCapeCod, n=0

 

If I do:

data dataset3;

set dataset1 dataset2;

run;

Dataset3;

City1 (label=city_name_very_too_long_to_be_a_nameChicago) City2 (label=city_name_very_too_long_to_be_a_nameCapeCod)

20                                                                                                   10

5                                                                                                      0

 

I am loosing the information related to my first Dataset1 (Boston and NewYork). Therefore, in Dataset3, I am assuming that 20 patients are coming from Chicago while they are coming from Boston.

 

Hope this is more clear.

 

 

 


Sounds like you want to rename the variables when the labels are different. 

Might be best to first transpose the data before combining it so that the data (name of city) is in a VARIABLE and not in metadata (variable LABEL).

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

It's not clear to me what "I want to keep the labels" means in this application. The resulting data set can have only one label per variable, so what is the desired output?

--
Paige Miller
Roger5
Calcite | Level 5

Hi,

Dataset1

name = city1, label=city_name_very_too_long_to_be_a_nameBoston, n=20

name = city2, label=city_name_very_too_long_to_be_a_nameNewYork, n=10

 

Dataset2

name = city1, label=city_name_very_too_long_to_be_a_nameChicago, n=5

name = city2, label=city_name_very_too_long_to_be_a_nameCapeCod, n=0

 

If I do:

data dataset3;

set dataset1 dataset2;

run;

Dataset3;

City1 (label=city_name_very_too_long_to_be_a_nameChicago) City2 (label=city_name_very_too_long_to_be_a_nameCapeCod)

20                                                                                                   10

5                                                                                                      0

 

I am loosing the information related to my first Dataset1 (Boston and NewYork). Therefore, in Dataset3, I am assuming that 20 patients are coming from Chicago while they are coming from Boston.

 

Hope this is more clear.

 

 

 

Tom
Super User Tom
Super User

@Roger5 wrote:

Hi,

Dataset1

name = city1, label=city_name_very_too_long_to_be_a_nameBoston, n=20

name = city2, label=city_name_very_too_long_to_be_a_nameNewYork, n=10

 

Dataset2

name = city1, label=city_name_very_too_long_to_be_a_nameChicago, n=5

name = city2, label=city_name_very_too_long_to_be_a_nameCapeCod, n=0

 

If I do:

data dataset3;

set dataset1 dataset2;

run;

Dataset3;

City1 (label=city_name_very_too_long_to_be_a_nameChicago) City2 (label=city_name_very_too_long_to_be_a_nameCapeCod)

20                                                                                                   10

5                                                                                                      0

 

I am loosing the information related to my first Dataset1 (Boston and NewYork). Therefore, in Dataset3, I am assuming that 20 patients are coming from Chicago while they are coming from Boston.

 

Hope this is more clear.

 

 

 


Sounds like you want to rename the variables when the labels are different. 

Might be best to first transpose the data before combining it so that the data (name of city) is in a VARIABLE and not in metadata (variable LABEL).

PaigeMiller
Diamond | Level 26

I still don't think you say what you WANT to happen, you just explain what does happen to the labels is not acceptable.

 

Perhaps you want to create a variable where it takes on values such as Boston, Chicago, New York, etc. Would that work for you?

--
Paige Miller
Tom
Super User Tom
Super User

When you combine datasets that contain the same variable then the label for the variable is set by the first dataset that actually has a label attached.  You can override it by adding a label statement to the step that combines the datasets. 

data one ;
  call missing(x,y,z);
  label x='X in ONE' y='Y in ONE';
run;
data two ;
  call missing(x,y,z);
  label Y='Y in TWO' z='Z in TWO';
run;
data both;
 set one two;
run;
proc contents data=both; run;

So if your preferred labels are on DATASET2 then list if first.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 809 views
  • 0 likes
  • 3 in conversation