proc sort data=together2;
by techid;
run;
data together3;
merge together2 (in=a) first_weight (in=b);
by techid;
if a and b;
run;
data together4;
set together3;
afc=calvingdate-dob;
run;
There's nothing in your code to indicate why that variable may be dropped. I modified your code, you really shouldn't be using the same input and output data set names when you're coding, it makes it really hard to find errors. Try the code above and if it still doesn't work, please post the code and your log. There's likely something there that indicates why this is happening.
@Hazelc wrote:
Hi,
I'm a beginner so please be kind! I need some help with the SAS code below, I am using two variables called calvingdate and dob to create a new variable called afc. However, I still need calvingdate to remain in my dataset (it disappears when I run the code below). Is there any command that will allow me to keep calvingdate while still creating the new variable afc? 🙂
proc sort data=together2;by techid;run;
data together2;merge together2 (in=a) first_weight (in=b);by techid;if a and b;run;
data together2;set together2;afc=calvingdate-dob;run;
Thanks in advance!:)