BookmarkSubscribeRSS Feed
Ameurgen
Obsidian | Level 7

Hello gays,

need help , as new sas programmer , i am in phase to finish my project so, i need to create a variable accally a binary variable  from my date, this is a type of date who i dealing with 

ANM_id     lact_no   start_date             service_date               NNR

111              1          2013-01-06             2013-03-15

111              1          2013-01-06             2013-04-04

111              2          2014-01-10             2014-04-21

111              2          2014-01-10            2014-05-10

222              1          2015-10-01            2015-11-15

222              2          2016-01-01            2016-02-06

222              2         2016-01-01             2016-02-26

i need to assign 1  if within a specific period (56 days)  from start date there will be one or more service date less than 56 days , otherwise NRR = 0  if there are a service after 56 days.

 

Thank all

 

Regards

2 REPLIES 2
ballardw
Super User

You should show some worked examples.

I am having a hard time following which values are compared for this: "i need to assign 1 if within a specific period (56 days) from start date there will be one or more service date less than 56 days , otherwise NRR = 0 if there are a service after 56 days."

Are you intending to use only the service_date for each observation or compare other dates?

 

IF your start_date and service_date are actual SAS date values you can get the number of days by either subtraction or the Intck function and the interval of days:

 

Days_between = service_date  - start_date;

or

Days_between= intck('day',start_date,service_date);

Kurt_Bremser
Super User
nnr = (0 <= (service_date - start_date) <= 56);

Assuming that your date values are stored as SAS date values.

For complete, tested code supply example data in a data step with datalines, so we can create an exact replica of your dataset with a simple copy/paste and submit.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 803 views
  • 0 likes
  • 3 in conversation