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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.