BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Barkamih
Pyrite | Level 9

 Hi

 I have a problem when I run this code in order to combine two datasets together by using this code, Calving_ease is the issue, this code can present only the number of calving_ease of the first dataset, but the numbers of calving_ease  in the second dataset are all missing.

 

regards 

 

data  dataall;

set data48 data910(rename=(calving_ease=calving_easenum));

calving_ease = put(calving_ease, 7.);

drop calving_easenum;

run;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

I made a small correction to your code:

assuming  calving_ease in 48 is character and 910 needs to become character

 

Try and let me know

 

data  dataall;

set data48 data910(in=b rename=(calving_ease=calving_easenum));

if b then calving_ease = put(calving_easenum, 7.);/*changed here to calving_easenum*/

drop calving_easenum;

run;

View solution in original post

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

In dataset date48 you have a variable called calving_ease, in data910 you also have this, however you rename it to calving_easenum  Now when these two datasets are set together the output creates a variable called calving_ease which holds the data from the first table, and fills in empties from the second, as that variable does not exist.  This is the logic you have presented below, and hence that is what is achieved at the end.  I cannot guess what you are trying to do, nor can I understand why your thread topic is char vs num but that is not what the question you present is.  A quick check on the guidance when presenting questions would help, present test data in the form of a datastep, show what you want out at the end.  I am going to guess that in one dataset calving_ease is character, and the other is numeric?  If so convert one or the other before setting.

Barkamih
Pyrite | Level 9

yeas 

your  guess is right because I had this issue I did this code, the normal code for  combining  data is this

 

data all;

set data1 data2;

run;

 

 but I have an error with the code as the calvng_ease defined as both character and numeric. 

so I tried to do it by the previous code that I posted,  but I got missing data for the second dataset 

 

 

novinosrin
Tourmaline | Level 20

@Barkamih you need to convert one of the variables to either character or numeric to make it consistent for successful append

Barkamih
Pyrite | Level 9

could you please provide an example code, how to convert it ?

 

novinosrin
Tourmaline | Level 20

I made a small correction to your code:

assuming  calving_ease in 48 is character and 910 needs to become character

 

Try and let me know

 

data  dataall;

set data48 data910(in=b rename=(calving_ease=calving_easenum));

if b then calving_ease = put(calving_easenum, 7.);/*changed here to calving_easenum*/

drop calving_easenum;

run;
Barkamih
Pyrite | Level 9

calving_ease of the second dataset are all missing by using this code Smiley Sad

novinosrin
Tourmaline | Level 20

Did you notice my edit in the previous message. Anyway, here is a demo

 

data have;
input var $;
datalines;
1
2
3
;

data have1;
input var;
datalines;
1
2
3
;

data want;
set have have1(in=b rename=(var=_var));
if b then var=put(_var,1.);
drop _var;
run;
novinosrin
Tourmaline | Level 20

Your approach is bang on correct. I think you are having a very minor problem:

 

instead of

calving_ease = put(calving_ease, 7.);

I changed the same to 

 

calving_ease = put(calving_easenum, 7.);

 plus instead of 

 

set data48 data910(rename=(calving_ease=calving_easenum));

I changed this to 

 

set data48 data910(in=b rename=(calving_ease=calving_easenum));

 

Barkamih
Pyrite | Level 9

thank you much, I appreciate that, you are done a very good jobe with me, and I'm sorry if I took you time 

 

best regards 

 

thanks again 

 

Barkamih 

novinosrin
Tourmaline | Level 20

@Barkamih  Hahaha nothing to be apologetic. We all learn and I am sure you share your knowledge too with tohers. Knowledge is meant to be shared and learning good things should a right. Take care and have a nice day!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 10 replies
  • 1914 views
  • 6 likes
  • 3 in conversation