SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Converting a datetime variable into two other date formats

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Converting a datetime variable into two other date formats

I have a datetime macrovariable called &extract_dttm, which has the value 31OCT12:23:59:59. Based on this, I need to create two additional macrovariables:

&period_dt, which should get the value 31OCT2012.

&period_yyyymm, which should get the value 201210.

Can someone please advise me on how to accomplish this in the precode of an Extract transformation?

Thank you.


Accepted Solutions
Solution
‎10-25-2012 08:03 AM
Super Contributor
Posts: 1,636

Re: Converting a datetime variable into two other date formats

Posted in reply to TurnTheBacon

24   %let d=31OCT12:23:59:59;

25   %let dd=%sysfunc(putn(%sysfunc(datepart("&d"dt)),date9));

26   %put ⅆ

31OCT2012

27   %let ddd=%sysfunc(putn("&dd"d,yymmn6.));

28   %put &ddd;

201210

View solution in original post


All Replies
Solution
‎10-25-2012 08:03 AM
Super Contributor
Posts: 1,636

Re: Converting a datetime variable into two other date formats

Posted in reply to TurnTheBacon

24   %let d=31OCT12:23:59:59;

25   %let dd=%sysfunc(putn(%sysfunc(datepart("&d"dt)),date9));

26   %put ⅆ

31OCT2012

27   %let ddd=%sysfunc(putn("&dd"d,yymmn6.));

28   %put &ddd;

201210

Super User
Super User
Posts: 7,039

Re: Converting a datetime variable into two other date formats

Posted in reply to TurnTheBacon

%let x=31OCT2012:23:59:59 ;

%let y=%sysfunc(putn("&x"dt,dtdate9.));

%let z=%sysfunc(putn("&y"d,yymmddn8.),$6.);

x=31OCT2012:23:59:59

y=31OCT2012

z=201210

Respected Advisor
Posts: 4,173

Re: Converting a datetime variable into two other date formats

Posted in reply to TurnTheBacon

%let extract_dttm=31OCT12:23:59:59;

%let period_dt=%sysfunc(inputn(&extract_dttm,datetime.),dtdate9.);

%put period_dt=&period_dt;

%let period_yyyymm=%sysfunc(inputn(&period_dt,date9.),yymmn6.);
%put period_yyyymmt=&period_yyyymm;

Respected Advisor
Posts: 3,799

Re: Converting a datetime variable into two other date formats

Posted in reply to TurnTheBacon

First create extract_dttm as a SAS datetime value.  Then you can write the value in any format with out having to do the conversion everything you need it.

%let extract_dttm = 31OCT12:23:59:59;

%let dt=%sysevalF("&extract_dttm"dt);

%let period_dt = %sysfunc(putn(&dt,dtdate,9));
%let period_yyyymm =%sysfunc(datepart(&dt),yymmn6);
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 531 views
  • 7 likes
  • 5 in conversation