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.
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
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
%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
%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;
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.