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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1246 views
  • 6 likes
  • 3 in conversation