- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Sowmya12,
If the first part of your data is always the year, then the below might help (assuming your date is character, based on what you've shown).
The scan() function selects part of string that is separated by a specific character(s).
data have;
input my_date : $char10.;
datalines;
2019/un/un
11/un/un
;
data want;
set have;
y = scan(my_date,1,'/');
run;
Kind regards,
Amir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
11 is not a year (2011 would be).
If you don't even know the order of the parts (YMD, DMY or MDY), you can't solve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Sowmya12,
If the first part of your data is always the year, then the below might help (assuming your date is character, based on what you've shown).
The scan() function selects part of string that is separated by a specific character(s).
data have;
input my_date : $char10.;
datalines;
2019/un/un
11/un/un
;
data want;
set have;
y = scan(my_date,1,'/');
run;
Kind regards,
Amir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would store year as a number with length 3. This allows years up to 8192, consumes the least space, and can be used in calculations or functions without conversion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
True.