BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have two data sets "data1" and "data2" and there are 3 variables in the data sets which are of same name but different type. These are:- variable1,variable2 and variable3 and these are NUM for dataset 2 and CHAR for dataset 1. How do I merge these datasets with different variable type??

I tried using INPUT and PUT but it didint work. Any suggestions?

Kind Regards,
Siddharth
1 REPLY 1
garybald
Calcite | Level 5
The first thing you need to decide is whether you want to keep the variables as numeric or character. Also consider if the variables are padded with leading zeros or anything else that may effect comparing the final values. Below is code I used to keep the variable NUMBER as a character when it was stored as numeric.

data temp (rename=(number2=number) drop=number);
length number2 $10;
set rev.mrc (keep = number);

number2 = put(number,z10.);

*NUMBER2 equals the numeric NUMBER with leading zeros. The original NUMBER is dropped, then NUMBER2 gets renamed to NUMBER in dataset temp.;

If you want to change the character variables to numeric, you can substitute code like this in the appropriate places:
length number2 8;
number2 = input(put(number,$10.),10.);
This converts the character to numeric.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 918 views
  • 0 likes
  • 2 in conversation