Hi guys,
I have a dataset DB with two variables: patient ID and date:
data DB;
ID date;
cards;
1 2013-11-13
2 2024-01-12
3 2025-01-10
4 2025-10-17
5 2024-11-15
6 2025-11-12
7 2025-10-08
;run;
I would like to format the date according to ISO 8601 standard for SDTM formatting. I'm new in the field.
I need a char variable at the end.
Can anyone help me please?
Thank you in advance
The E8601DA10. format, which is equivalent to the YYMMDD10. format, will accomplish this, either in a PUT() function or PUT statement.
It is not clear what you are starting with since the code you shared cannot run.
If the variable you named DATE is an actual SAS date variable then it is NUMERIC. In order to create a CHARACTER variable you will need to use a different variable name. And if it is an actualy date variable it cannot contain any partial date values, so you can ignore the SDTM specifications for how to represent partial date values.
To convert a date value into a character value in the style YYYY-MM-DD you can either the YYMMDD10. format, Or the YYMMDDD10. format, the extra D stands for DASH. Or use the E8601DA10. format.
data want;
set db;
charvar=put(date,yymmdd10.);
run;
If your variable is character and looks like the text in your example then you don't need to do anything since it is already in that style.
Hi @NewUsrStat , the syntax of the code in your question is incorrect. With the correct syntax, the code DOES produces date values in standard ISO8601 form. To be more specific, (1) you should have input in the second statement, (2) use $10. informat for your date variable, this produces a correct ISO8601 date form (and its type is character10, i.e., $10.), (3) a date value displayed like yyyy-mm-dd, e.g. 2013-11-13, is correct ISO8601 form. (4) A question for your, why do you need character type date values in SDTM dataset? Would numeric type be more easier for computing date values?
The correct syntax is as follows:
data DB;
input ID date $10.;
cards;
1 2013-11-13
2 2024-01-12
3 2025-01-10
4 2025-10-17
5 2024-11-15
6 2025-11-12
7 2025-10-08
;
run;
proc contents data=db;run;
proc print data=db;run;
Hi @NewUsrStat , I think what you would like to do is create a numeric date column displayed in ISO8601 form (with this form, the values are displayed as characters, but the type of the variable is numeric), and I think this is the common practice for date values. Hope this answer your question. The code is as follows:
data DB;
input ID date yymmdd10.;
format date yymmdd10.;
cards;
1 2013-11-13
2 2024-01-12
3 2025-01-10
4 2025-10-17
5 2024-11-15
6 2025-11-12
7 2025-10-08
;
run;
proc contents data=db;run;
proc print data=db;run;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.