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

Hello everyone,

i would appreciate your help as i'm stuck.

 

i want to calculate a study period by using "beginning of the study" variables (2 variables: month and year ) and the "end of the study variables" ( month and year). i tried concantenating the month and year period for begginning and end of the study but i dont know how else to go about it

example of what i want :  if beginning date (ddmmyy) is 01082010 and end date is 01072011(ddmmyy), i want a new variable titled "study_period" which will have a value of 12 (i.e 12 months since the difference in the dates is a year).

these date variables ic reated using catt function is character

thank you


DATA TRIAL;
Set TCR.DUMMY4;
Col_beg = catt(1,FirstRxDtSEERMonth,FirstRxDtSEERYear); 
/** these are the variables for the beginning of the study; i added 1 as the first day of the month, followed by the time in month, and then in year**/
Col_end = catt(1,datelastcontmonth,datelastcontyear);
/** these are the variables for the end of the study; i added 1 as the first day of the month, followed by the time in month, and then in year**/
Run;

PROC PRINT DATA = TRIAL (OBS = 10);
VAR COL_beg col_end;
RUN;


DATA TRIAL2; Set Trial;
date_beg = input(col_beg,ddmmyy10.); /**trying to convert to date format but didnt work**/ date_end = input(col_end,ddmmyy10.); /*log error: Invalid argument to function INPUT at line 49 column 12.*/
run;
run;

sas outputsas output

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If your month and year variables are numeric use MDY() function to generate dates.

date=mdy(month,1,year);

If your month and year variables are character use INPUT() function to generate dates.

date=input(catx('/',month,1,year),mmddyy10.);

Once you have two date values use INTCK() to count months.

interval=intck('month',date1,date2);

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

If your month and year variables are numeric use MDY() function to generate dates.

date=mdy(month,1,year);

If your month and year variables are character use INPUT() function to generate dates.

date=input(catx('/',month,1,year),mmddyy10.);

Once you have two date values use INTCK() to count months.

interval=intck('month',date1,date2);
Banke
Pyrite | Level 9

Thank you so much! it worked!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1423 views
  • 1 like
  • 2 in conversation