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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

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

Tom
Super User Tom
Super User

%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

Patrick
Opal | Level 21

%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;

data_null__
Jade | Level 19

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);

sas-innovate-2024.png

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.

 

Register now!

How to connect to databases in SAS Viya

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.

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