Hi folks,
I have a date variable with two different date formats; like 201703 and 20170319.
How do I re-code to generate a single format please?
Ta
Hi,
The data is stored in a CSV
Thanks
I would suggest to use a data step to read the CSV file.
1. Then read the particular variable as a character.
2. add some default date when the date field is absent.
3. Convert the char date to number date.
Example code snippet.
data have;
input f_date:$8.;
if length(f_date)<8 then t_date=cats(f_date,'01'); /*01 is some random number*/
else t_date=f_date;
a_date=input(t_date,yymmdd8.);
cards;
201703
20170319
;
run;
Hi Satish,
I have tried to run the code as you have suggested but I think I want to do it differently. My Date of Birth variable has values like '201702' and some values are missing.
And Attendance_date has two different formats like; 201903 and 20150623.
I have read the two fields as character $8.
I want to do following;
Derive the age of participants from Dob and attendance_date. Please suggest the best possible way.
Thanks
@sks521 wrote:
Hi Satish,
I have tried to run the code as you have suggested but I think I want to do it differently. My Date of Birth variable has values like '201702' and some values are missing.
And Attendance_date has two different formats like; 201903 and 20150623.
I have read the two fields as character $8.
I want to do following;
Derive the age of participants from Dob and attendance_date. Please suggest the best possible way.
Thanks
Please provide explicit examples of your input and the desired actual date you want them treated as.
And do you want Age in years as commonly done or year and fractional part or some other unit?
The first step is going to settle on a base rule for the incomplete dates. So specify if that 201903 is supposed to be the first day of March in 2019, another day in March in 2019, or something else. Note that 6 character dates can have lots of interpretations and you need to explicitly tell us what you want to use.
Example: 010203 could be 02JAN2003 , 03Feb2001, 01Feb2003 or the years might be 1903, 1901 or 1903. Any 2 digit year is hightly suspect in my book.
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.