BookmarkSubscribeRSS Feed
Francisco_Cab
Calcite | Level 5

Hi all,

 

I have a large data set with ID, PARITY, BREEDING DATE, FARROWING DATE AND WEANING DATE variables. I need to create a new variable that can show the weaning date of the previous PARITY within the same ID. In all PARITY 1 I need a "." in the NEW VARIABLE.

 

This is what I need to achieve:

 

 

Image.png

Any help provided will be greatly appreciated!!!

 

Best regards,

Francisco

1 REPLY 1
Tommy1
Quartz | Level 8

Try using a lag variable. I have not tested it but how about something like;

 

proc sort data=have;

by id parity;

run;

 

data want;

set have;

new_variable=lag(weaning_date);

if first.id then new_variable=.;

run;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 399 views
  • 0 likes
  • 2 in conversation