BookmarkSubscribeRSS Feed
Almighty
Fluorite | Level 6

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

8 REPLIES 8
Hima
Obsidian | Level 7

data want(keep=patid age visdate);
RETAIN patid age visdate;
set have;

age=cat('P',ageyears,'Y',agemon,'M');
RUN;

Capture.JPG

Almighty
Fluorite | Level 6

Thanks Hima,

Instead of cat is there any other way we can do?

Thanks again

Hima
Obsidian | Level 7

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;

Almighty
Fluorite | Level 6

Thanks Again Hima.

Is there another way using ISO8601 (duration) formats.

Thanks

Hima
Obsidian | Level 7

From the link below, I dont see any such format.

Dates, Times, and Intervals : SAS Date, Time, and Datetime Values

dkb
Quartz | Level 8 dkb
Quartz | Level 8

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.

jakarman
Barite | Level 11

Using intnx interval functions should do the job

---->-- ja karman --<-----
jakarman
Barite | Level 11

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.

---->-- ja karman --<-----

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 8 replies
  • 1572 views
  • 1 like
  • 4 in conversation