Hi Everyone,
I am totally new to sas and I am trying to find a way to specify a particular month when creating my date variable. I have included the problem question in the comment of my code.
/*Question 4: Using the Hosp SAS dataset, create a new temporary SAS dataset which contains only patients born after August 05, 1950. Extract the day from the birth date (DOB) and the year from the admission date (AdmitDate). Create a new date variable named DateNew using these 2 variables and the month of May.Calculate each patient's age as of January 27, 2018. And using a date interval function with the ‘sameday’ option, identify a scheduled return visit date that is 5 months after the discharge date. Format all dates as YYYY-MM-DD and print observations for patients who have IDs between 15 and 45 inclusive.*/;
libname cb "I:\My Documents\552\codybook";
data thosp;
set cb.hosp (where = (DOB gt '05Aug1950'd));
/*Extracting day and year from DOB and AdmitDate Respectively*/
dy = day(DOB);
yr = year(AdmitDate);
mnth = mnth(‘May’);
DateNew = mdy(mnth,dy,yr);
Age = yrdif(DOB,'27Jan2018'd);
ReturnVisitDate =intnx('month', DischrDate, 5, 'sameday');
format DOB yymmdd10. ReturnVisit yymmdd10. AdmitDate yymmdd10. DateNew yymmdd10. DischrDate yymmdd10.;
run;
proc contents data = thosp;
run;
proc print data = thosp (obs=2);
run;
proc print data = thosp;
where ID in (15:45);
run;Please see the attached screenshot error I keep getting and my code below:
Welcome to the Forum!
The error message says it: there is no function named mnth. There is no need for such a function.... you can just write mnth = 5;
The other message is caused by a missing semicolon, an error that's already fixed in your posted code.
Good luck!
Welcome to the Forum!
The error message says it: there is no function named mnth. There is no need for such a function.... you can just write mnth = 5;
The other message is caused by a missing semicolon, an error that's already fixed in your posted code.
Good luck!
Yes I realized that too! Thank you!
Fixed Code
libname cb "I:\My Documents\552\codybook";
data thosp;
set cb.hosp (where = (DOB gt '05Aug1950'd));
/*Extracting day and year from DOB and AdmitDate Respectively*/
dy = day(DOB);
yr = year(AdmitDate);
mnth = 5;/*May*/
DateNew = mdy(mnth,dy,yr);
Age = yrdif(DOB,'27Jan2018'd);
ReturnVisitDate =intnx('month', DischrDate, 5, 'sameday');
format DOB yymmdd10. ReturnVisit yymmdd10. AdmitDate yymmdd10. DateNew yymmdd10. DischrDate yymmdd10.;
run;
proc contents data = thosp;
run;
proc print data = thosp (obs=2);
run;
proc print data = thosp;
where ID in (15:45);
run;SAS Month function Returns the month from a SAS date value, it does not convert May to 5.
Please let us know if it worked for you.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.