BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Solly7
Pyrite | Level 9

Hi, i need help in changing below dates formats

 

DATA HAVE                          DATA WANT

 

190125                                  25JAN2019

180809                                  09AUG2018

170111                                  11JAN2017                     

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

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;

dates.gif

 

 

View solution in original post

1 REPLY 1
ErikLund_Jensen
Rhodochrosite | Level 12

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;

dates.gif

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 1 reply
  • 210 views
  • 0 likes
  • 2 in conversation