BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

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

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
monday89
Fluorite | Level 6

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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 750 views
  • 0 likes
  • 2 in conversation