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

Hello. I am trying to convert a numeric date variable into a character. Code below. Please advise.

 

*previous step;
data have1; set have;
gap_months=birthdate-admdate;
format gap_months month.;
run;

*This provided me with the difference in months from the birth hospital visit to
the hospital readmission . Now I want to turn the variable gap_months into a character;


I tried the following, it didn't work - any suggestions? thank you;

data want; set have1;
 gap_monthschar=  put(input( gap_months,best.),z2.);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

gap_months is, per definition from the previous step, numeric, so the conversion with the input() function is not necessary.

From your code I infer that birthdate and admdate are SAS dates, and to calculate the month difference between dates, one uses the intck() function:

gap_months = intck('month',birthdate,admdate,'c');

and then

gap_monthschar = put(gap_months,z2.);

both can be done in one step.

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

More than the code, a sample data of what you 'have' and what you 'want' will help many understand better plz

eabc0351
Quartz | Level 8

Yes, sorry about that. I figured it the syntax in the meantime. I was looking for the function month(). This helped me get the month of both dates in a format that I wanted. @novinosrin Thank you for your reply. 

Kurt_Bremser
Super User

gap_months is, per definition from the previous step, numeric, so the conversion with the input() function is not necessary.

From your code I infer that birthdate and admdate are SAS dates, and to calculate the month difference between dates, one uses the intck() function:

gap_months = intck('month',birthdate,admdate,'c');

and then

gap_monthschar = put(gap_months,z2.);

both can be done in one step.

eabc0351
Quartz | Level 8

Great @Kurt_Bremser . That solution worked, thank you.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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