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

The two following code lines, which are taken from a DATA step, need to be rewritten so that they can be used in a macro:

%call symput('startdato', %put(intnx('week',today(), -1, 'beginning')+2, nordfde9.));

%call symput('sluttdato', %put(intnx('week',today(), 0, 'beginning')+1, nordfde9.));

At first I figured I might do it like this:

%let startdato = %intnx('week',today(), -1, 'beginning') +2;

%let sluttdato = %intnx('week',today(), 0, 'beginning') +1;

%put(startdato, nordfde9.);

%put(sluttdato, nordfde9.);

However, apparently that doesn't work. Can someone please advise me on how to resolve this?

Thanks. Smiley Happy

UPDATE: What I need is create a macrovariable that says for example "02oct2012-08oct2012" (if the job was run today). The INTNX-logic works in a DATA step, so that's not a problem. I can write %let week_period = &sysdate.-&sysdate.; to get 10OCT12-10OCT12, but how do I apply the INTNX and formatting properly in DI Studio precode?

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Using a shifted interval makes it a bit easier.  I think :smileyplain:

22         %let startdato = %sysfunc(intnx(week1.3,%sysfunc(today()),-1,b),nordfde9.);

23         %let sluttdato = %sysfunc(intnx(week1.3,%sysfunc(today()),-1,e),nordfde9.);

24         %put &startdato - &sluttdato;

02okt2012 - 08okt2012

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

I wrote the following before I saw your update.  Can you expand it to do what you need?:

%let startdato = %sysfunc(putn(%eval(%sysfunc(intnx(week,%sysfunc(today()), -1, beginning)) +2),nordfde9.));

%let sluttdato = %sysfunc(putn(%eval(%sysfunc(intnx(week,%sysfunc(today()), 0, beginning)) +1),nordfde9.));

%put &startdato;

%put &sluttdato;

data_null__
Jade | Level 19

Using a shifted interval makes it a bit easier.  I think :smileyplain:

22         %let startdato = %sysfunc(intnx(week1.3,%sysfunc(today()),-1,b),nordfde9.);

23         %let sluttdato = %sysfunc(intnx(week1.3,%sysfunc(today()),-1,e),nordfde9.);

24         %put &startdato - &sluttdato;

02okt2012 - 08okt2012

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 2 replies
  • 1238 views
  • 3 likes
  • 3 in conversation