Hi
I have data like below:
HAVE:
patid ageyears agemon visdate
001 7 10 2014-02-10
003 15 6 2014-01-15
NEEDED like below:
patid age visdate
001 P7Y10M 2014-02-10
003 P15Y6M 2014-01-15
Can Guru's help me with populating age as above
Thanks in advance
data want(keep=patid age visdate);
RETAIN patid age visdate;
set have;
age=cat('P',ageyears,'Y',agemon,'M');
RUN;
Thanks Hima,
Instead of cat is there any other way we can do?
Thanks again
Another way that I know,
data want(keep=patid age visdate);
RETAIN patid age visdate;
set have;
age='P'||TRIM(LEFT(ageyears))||'Y'||TRIM(LEFT(agemon))||'M';
RUN;
Thanks Again Hima.
Is there another way using ISO8601 (duration) formats.
Thanks
From the link below, I dont see any such format.
Dates, Times, and Intervals : SAS Date, Time, and Datetime Values
ISO 8601 formats are available in v9 and are documented here:
SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition
But personally I find them rather fiddly and I think Hima's suggestions are good.
Using intnx interval functions should do the job
As everyone can work with his own calendar and clock there are many possibilities. But wanting to understand each other is needing an agreement that we use some standard.
For clock/time we have gmt hours/seconds being defined. For dates the iso-standards (8601) are becoming getting accepted. The metric system still being difficult for acceptance Metric system - Wikipedia, the free encyclopedia. We could have done for the French revolutions way French Republican Calendar - Wikipedia, the free encyclopedia. Little chance for those now. Date/time calculations are not that easy in a Georgian approach there is a 28-year period. Week-numbers are overlapping in the year-change.
The data/time convention with SAS as a number since the arbitrary point of zero 1 jan 1960 0:0:0 is a good way for calculations.
For date/time duration calculations intck: SAS(R) 9.3 Functions and CALL Routines: Reference
For advancing back and up in time intnx: SAS(R) 9.3 Functions and CALL Routines: Reference
For presenting something age in a structure PyyMdd use formats. In this case the string is varying between 4 and 6. (advice fix that on 6, usage of blanks or zeros)
Of course you can manipulate strings as you did with pencil and paper. At some moment you will find that getting very complicated when using computers.
Suppose you are needing to recalculate after some time, knowing the birthday or making a good guess of that. It is about data quality.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.