Hi all,
I got error by using both of theses codes in order to merge two datasets
Data data2004;
merge d2004 county; by herd; run; quit;
data Data2004;
merge D2004(IN=K) county(IN=Q);
if K and Q; by herd; run; quit;
and this the log:
355 data Data2004;
356 merge D2004(IN=K) county(IN=Q);
ERROR: Variable HERD has been defined as both character and numeric.
357 if K and Q; by herd; run;
regards
Ibrahim
Given your data, a big enough w. informat (eg 12.) will do it. But if you start from a csv file, the optimal way is reading the column as numeric in the first place.
I think the error message is relatively clear. You have to fix the problem so in both data sets HERD is numeric, or in both data sets HERD is character.
i did this code but to convert the variable, but how to complete it correctly?
data county;
herd = ' ';
new_herd = input(herd, );
drop herd;
rename new_herd = herd;
run;
Which informat you have to use in the input() function depends on the contents of herd. That's why we need examples.
In many cases, the BESTw. informat can work.
How did you create these data sets initially? Did you verify the variable types were imported correctly and what you need?
If not, you need to go back and do that step.
@Barkamih wrote:
Hi all,
I got error by using both of theses codes in order to merge two datasets
Data data2004; merge d2004 county; by herd; run; quit; data Data2004; merge D2004(IN=K) county(IN=Q); if K and Q; by herd; run; quit;
and this the log:
355 data Data2004;
356 merge D2004(IN=K) county(IN=Q);
ERROR: Variable HERD has been defined as both character and numeric.
357 if K and Q; by herd; run;regards
Ibrahim
how to make it correct?
data county;
herd = ' ';
new_herd = input(herd, );
drop herd;
rename new_herd = herd;
run;
Provide example data, so we can guide you to the correct informat.
Hi, I'm really sorry about that, I was so busy yesterday,
this is an example of the herd variable
so, I have big data that has these numbers and I want to merge some information to these file by a herd.
Herd number means Farm name or farm id,
I got these data in excel file form a company.
data was imported to SAS as a CSV file type.
I'm really confused about how to merge these file together.
best regards to everyone
Ibrahim
Herd
5179940
5180223
5599499
60001827
390464233
700114030
1206840374
It doesn't help if you type in the data from ONE of the data sets. Typing in the data doesn't help anyway. You have to show us the code that shows how BOTH (not one) data sets were created. Or show us PROC CONTENTS output of BOTH data sets.
this is data county
herd | Num | 8 | BEST12. | BEST32. |
herd |
YES |
ANSI |
this is data d 2004
HERD | Char | 42 | $42. | $42. |
@Barkamih wrote:
data was imported to SAS as a CSV file type.
Since you are reading from a text file you can have complete control over how the variables are created.
You probably used PROC IMPORT to read the files. That will just generate a data step to read the file. Copy the data steps and modify the definition of HERD to be the same for both. Then re-run the modified data steps and now your HERD variable will be compatible.
Given your data, a big enough w. informat (eg 12.) will do it. But if you start from a csv file, the optimal way is reading the column as numeric in the first place.
you need to fix the data type in your contributing tables, there is no issue with your merge code
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.