i have to merge two files by two variables company and year. when i tried it in SAS, it was not successful.
then i created a new variable by combining the values of both company and year and naming it has "compyear".
it worked for one time. next time, when it tried the same procedure, I am facing the following problem.
209 data master_fil4;
210 merge Master_file_latest Ta__new; by compyear;
ERROR: Variable year has been defined as both character and numeric.
211 run;
i am not using variable 'year' in merging the files, i am using only 'compyear'
kindly help me in solving this problem.
thanks in advance
The variable year is character in one of your data sets and numeric in the other. Convert it to numeric in the data set where it is character before you merge.
You can use PROC CONTENTS to identify
Maxim 3: Know Your Data
Before merging, make sure that the only variable(s) present in both (or all, if you merge more than two) datasets are those in the by statement.
Having others in common leads to largely unpredictable results and is therefore a BAD THING.
Use keep= or drop= dataset options to exclude variables you do not want, or use a rename= dataset option for renaming, so the variables can exist in parallel in the body of the data step, where you can decide what to do with the values.
Also have an eye on the relationship with regards to the by variables. Data step merge is not good for many-to-many relationships, it's best for one-to-one or one-to-many.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.