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

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:

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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!

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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!

PG
cheenaChuks
Obsidian | Level 7

Yes I realized that too! Thank you!

Satish_Parida
Lapis Lazuli | Level 10

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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