Help using Base SAS procedures

SAS dates question

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

SAS dates question

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.

Attachment

Accepted Solutions
Solution
‎03-23-2012 03:50 PM
SAS Super FREQ
Posts: 8,781

Re: SAS dates question

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


All Replies
Solution
‎03-23-2012 03:50 PM
SAS Super FREQ
Posts: 8,781

Re: SAS dates question

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;

New Contributor
Posts: 2

SAS dates question

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

Thank you again. You're awesome!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 293 views
  • 0 likes
  • 2 in conversation