BookmarkSubscribeRSS Feed
olivia123456
Fluorite | Level 6

how do you merge two data sets and create an identifier between two common variables (changing a variable to numerical or one to character)

1 REPLY 1
ballardw
Super User

You should provide example data of the two data sets and what you expect as a result. Data is best in the form of a data step.

 

Note that if the variable in two or more data sets for Merge or Set with the same name has different types then SAS will throw an error and not allow any execution of the data set. You will need to either rename the variable so they don't have the same name or in a prior step go the dance to create a different data set with the proper type variable.

 

Here's an example of "fixing" a character variable that should have been numeric:

data have;
  input x $;
datalines;
1223
456
;
run;

data want;
   set have(rename=(x=oldx));
   x=input(oldx,f5.);
run;

The numeric to character case involves a PUT statement with the proper format.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 373 views
  • 0 likes
  • 2 in conversation