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!
@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).
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?
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.
@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).
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?
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.
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.