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;
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.
More than the code, a sample data of what you 'have' and what you 'want' will help many understand better plz
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.
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.
Great @Kurt_Bremser . That solution worked, thank you.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.