Help using Base SAS procedures

comning data sets with variables having different type

Not applicable
Posts: 0

comning data sets with variables having different type


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,
Posts: 29

Re: comning data sets with variables having different type

Posted in reply to deleted_user
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.
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation