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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 358 views
  • 0 likes
  • 2 in conversation