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

Hi, I am trying to use proc sql to convert a character date format YYYYMMDD to a number date format YYYYMMDD.

 

,put(intnx('month', input(strip(put(a.ISSUDATE,8.)),yymmdd10.), -1, 'e'), yymmddn8.) as RTfile_date

So currently,  my input 'a.ISSUDATE' is a numeric date variable with format as YYYYMMDD, and my returned 'RTfile_date' is a character with the format YYYYMMDD. How can I change it to a numberic with the same format? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Currently you are using PUT() with YYMMDDN8. format to generate a string like '20191231'.

Do you want to generate a date value and attach the YYMMDDN8. (or better the YYMMDD10.) format to the variable?

intnx('month',input(put(a.ISSUDATE,Z8.),yymmdd8.),-1,'e')
  as RTfile_date format=yymmddn8.

Or do you want to return a number like 20,191,231 and attach the 8. format to it so it looks like 20191231 when displayed?

input(put(intnx('month',input(put(a.ISSUDATE,Z8.),yymmdd8.),-1,'e'),yymmddn8.),8.)
  as RTfile_date format=8.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data a;
    date='20191210';
	date_n=input(date,yymmdd8.);
	format date_n yymmddn8.;
run;

I point out that there is no such thing as a numeric YYYYMMDD, as SAS dates are integers representing the number of days since 1/1/1960. Thus, you need to apply a format so it looks to us humans as 20191210.

--
Paige Miller
Tom
Super User Tom
Super User

Currently you are using PUT() with YYMMDDN8. format to generate a string like '20191231'.

Do you want to generate a date value and attach the YYMMDDN8. (or better the YYMMDD10.) format to the variable?

intnx('month',input(put(a.ISSUDATE,Z8.),yymmdd8.),-1,'e')
  as RTfile_date format=yymmddn8.

Or do you want to return a number like 20,191,231 and attach the 8. format to it so it looks like 20191231 when displayed?

input(put(intnx('month',input(put(a.ISSUDATE,Z8.),yymmdd8.),-1,'e'),yymmddn8.),8.)
  as RTfile_date format=8.
newboy1218
Quartz | Level 8
I think your 2nd solution works perfectly for me! Thank you so much 😃
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 10787 views
  • 2 likes
  • 3 in conversation