I have two dataset with different variable formats
dataset #1
reasons | group1 | group2 |
reason1 | 1 (6%) | 10 (48%) |
reason2 | 4 (22%) | 7 (33%) |
reason3 | 6 (33%) | 1 (5%) |
reason4 | 7 (39%) | 3 (14%) |
group1 and group2 format are both $22.;
dataset2;
reasons | group1 | group2 |
TOTAL | 18 | 21 |
group1 and group2 are best12.;
i want to combine using UNION both tables to this:
reasons | group1 | group2 |
reason1 | 1 (6%) | 10 (48%) |
reason2 | 4 (22%) | 7 (33%) |
reason3 | 6 (33%) | 1 (5%) |
reason4 | 7 (39%) | 3 (14%) |
TOTAL | 18 | 21 |
I did:
proc sql;
create table want_merge as
select * from dataset1
union all
select * from dataset2;
quit;
I am getting error "group 1 has been defined as both character and numeric' . i changed the format in each dataset to 22.; but still not work
We'd need to see your actual SAS data sets, and how they were created. What you have shown us is not a SAS data set, it is an output from a PROC, and non-informative.
In any event, in the creation of data set #1 and data set #2, somehow you have created group1 as numeric in one and group1 as character in the other, and that has to be fixed so they are both character, or both numeric.
Yes, I understand. Dataset1 is derived dataset for calculations and dataset2 is the denominator.
dataset1 | |||
Variable | Type | Len | Label |
reasons | Char | 1000 | |
group1 | Char | 22 | |
group2 | Char | 22 |
dataset2 | |||
Variable | Type | Len | Label |
reasons | Char | 5 | |
group1 | Num | 8 | |
group2 | Num | 8 |
I am trying forcing all variables to be character format. Not so much worried about what is in it. THANK YOU
So you have to create these data sets differently, so that group1 is numeric in both (or character in both); and the same for group2.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.