Hi, i need help in changing below dates formats
DATA HAVE DATA WANT
190125 25JAN2019
180809 09AUG2018
170111 11JAN2017
Hi @Solly7
You don't provide many informations. Are your input dates a number or a character string? - and do you want your output as a SAS date value (number of days since jan 1, 1960) with a format to show the date in reports as ddmonyyyy, or do you want a text string with the date in ddmonyyyy-format? -
This covers all combinations. The dates are converted to SAS data values, and the values with format and converted to string:
* test input: dates as numbers and strings;
data have;
input date cdate$;
cards;
190125 190125
180809 180809
170111 180809
;
run;
data want; set have;
sas_date = input(put(date,6.),yymmdd6.); * SAS-date from num input;
sas_cdate = input(cdate,yymmdd6.); * SAS-date from char input;
format fmt_sas_date date9.; * format to display SAS dates as ddmonyyyy;
fmt_sas_date = sas_date; * SAS date value with format to show as ddmonyyyy;
str_date = put(sas_date,date9.); * formatted ddmonyyyy-string from SAS date value;
run;
Hi @Solly7
You don't provide many informations. Are your input dates a number or a character string? - and do you want your output as a SAS date value (number of days since jan 1, 1960) with a format to show the date in reports as ddmonyyyy, or do you want a text string with the date in ddmonyyyy-format? -
This covers all combinations. The dates are converted to SAS data values, and the values with format and converted to string:
* test input: dates as numbers and strings;
data have;
input date cdate$;
cards;
190125 190125
180809 180809
170111 180809
;
run;
data want; set have;
sas_date = input(put(date,6.),yymmdd6.); * SAS-date from num input;
sas_cdate = input(cdate,yymmdd6.); * SAS-date from char input;
format fmt_sas_date date9.; * format to display SAS dates as ddmonyyyy;
fmt_sas_date = sas_date; * SAS date value with format to show as ddmonyyyy;
str_date = put(sas_date,date9.); * formatted ddmonyyyy-string from SAS date value;
run;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.