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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.