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

Hi, I'm new to sas, my teacher gave us a data set and he asked us to set scheduled dates to the last of the month if the initial visit dat was on the last of the month. I have been going crazy for 3 days now and I can't figure it out. Any help would be appreciated. Thank you. I am uploading the files so you can see what I'm dealing with.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I am always reluctant to do someone's homework, since I believe that part of education is learning how to do things on your own by doing homework. However, I am always happy to provide an example that may point you in the right direction.

  First, I'm not entirely sure what you mean when you say that you need to "set scheduled dates to the last of the month if the initial visit dat was on the last of the month". But it sounds like you need to calculate an interval by taking a date that you need to "start from" and then find out what some date is, given a known interval. So, for example, let's say that I have this data:

LAST  FIRST   VISIT_DATE

Allen Andy    03/31/2009

Bond Bobby    12/29/2010

Chase Candy   07/25/2001

Davis Dan     04/30/1983

Edwards Eliza 03/24/2012

and, as you can see, some of the visit dates fall on the last day of the month and some of the dates do NOT fall on the last day of the month. I can use the INTNX function to create a new variable that will be the last day of the "same" month or the last day of the "next" month. The documentation for the INTNX function outlines the arguments and intervals that you can use. In my example, I calculate two new variables. You should be able to run the attached program and review the output. Between that and consulting the documentation, I think you may find the INTNX function to be useful.

cynthia

data fakedata;

  infile datalines dlm=' ' ;

  input last_name $ first_name $ visit_date : mmddyy10.;

  end_of_same_month = intnx('month',visit_date,0,'e');

  end_of_next_month = intnx('month',visit_date,1,'e');

return;

datalines;

Allen Andy    03/31/2009

Bond Bobby    12/29/2010

Chase Candy   07/25/2001

Davis Dan     04/30/1983

Edwards Eliza 03/24/2012

;

run;

  

ods listing;

proc print data=fakedata;

  var last_name first_name visit_date end_of_same_month end_of_next_month;

  format end_of_same_month end_of_next_month visit_date mmddyy10.;

run;

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  I am always reluctant to do someone's homework, since I believe that part of education is learning how to do things on your own by doing homework. However, I am always happy to provide an example that may point you in the right direction.

  First, I'm not entirely sure what you mean when you say that you need to "set scheduled dates to the last of the month if the initial visit dat was on the last of the month". But it sounds like you need to calculate an interval by taking a date that you need to "start from" and then find out what some date is, given a known interval. So, for example, let's say that I have this data:

LAST  FIRST   VISIT_DATE

Allen Andy    03/31/2009

Bond Bobby    12/29/2010

Chase Candy   07/25/2001

Davis Dan     04/30/1983

Edwards Eliza 03/24/2012

and, as you can see, some of the visit dates fall on the last day of the month and some of the dates do NOT fall on the last day of the month. I can use the INTNX function to create a new variable that will be the last day of the "same" month or the last day of the "next" month. The documentation for the INTNX function outlines the arguments and intervals that you can use. In my example, I calculate two new variables. You should be able to run the attached program and review the output. Between that and consulting the documentation, I think you may find the INTNX function to be useful.

cynthia

data fakedata;

  infile datalines dlm=' ' ;

  input last_name $ first_name $ visit_date : mmddyy10.;

  end_of_same_month = intnx('month',visit_date,0,'e');

  end_of_next_month = intnx('month',visit_date,1,'e');

return;

datalines;

Allen Andy    03/31/2009

Bond Bobby    12/29/2010

Chase Candy   07/25/2001

Davis Dan     04/30/1983

Edwards Eliza 03/24/2012

;

run;

  

ods listing;

proc print data=fakedata;

  var last_name first_name visit_date end_of_same_month end_of_next_month;

  format end_of_same_month end_of_next_month visit_date mmddyy10.;

run;

Dezod
Calcite | Level 5

Thank you so much! I was going crazy for three days straight. Now I can breath again.

Thank you again. You're awesome!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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