BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8

Suppose I have Date 25Dec2022 and I have declared it as date. Now I want it to increment the date every time I run it.

After running the code it should be 26Dec2022 and Again If we ran that code it should be 27Dec2022 and so on..

Can anyone suggest how should I proceed with it.

I think INTNX function would be useful but how would I automate this process After I have declared it once.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Kirito1 wrote:

I want to do something like this but this is just normal a normal counting this code is doing. I am applying this code on a dataset I want it to update every time it reads the data.

For example: 

DATA B; SET A (where=('DATE_OF_APPROVAL'N GE '01DEC2022'D));

I have hard coded the date here but if I run this data on 02Dec2022 I don't want to specify the Date everytime I run the code.

I somehow want to use the below code to update 'DATE_OF_APPROVAL' everytime  I run this code.


 

I think what you want is the TODAY() function. The is no incrementing here.

 

DATA B; 
SET A (where=(DATE_OF_APPROVAL GE today()));
run;

 

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

 You can increment dates by arithmetic. You want to simply add 1 to the date variable.

 

It is not clear if you want to do this in a data step or in a macro variable or somewhere else, so I offer no example of doing this. Please clarify.

 

Terminology : unlike other computer languages, in SAS you cannot "declare" anything. The variable either is a date variable or it is not a date variable.

--
Paige Miller
Kirito1
Quartz | Level 8
How do I increment date by arithmetic can you provide any syntax for that. I want to apply this on a data step.
PaigeMiller
Diamond | Level 26

You add 1 to the variable. I cannot provide example code because I asked you to clarify something, but you did not do so. I said: "It is not clear if you want to do this in a data step or in a macro variable or somewhere else, so I offer no example of doing this. Please clarify."

--
Paige Miller
Kirito1
Quartz | Level 8

I want to do something like this but this is just normal a normal counting this code is doing. I am applying this code on a dataset I want it to update every time it reads the data.

For example: 

DATA B; SET A (where=('DATE_OF_APPROVAL'N GE '01DEC2022'D));

I have hard coded the date here but if I run this data on 02Dec2022 I don't want to specify the Date everytime I run the code.

I somehow want to use the below code to update 'DATE_OF_APPROVAL' everytime  I run this code.

%macro date_loop(start,end);
   %let start=%sysfunc(inputn(&start,anydtdte9.));
   %let end=%sysfunc(inputn(&end,anydtdte9.));
   %let dif=%sysfunc(intck(month,&start,&end));
     %do i=0 %to &dif;
      %let date=%sysfunc(intnx(month,&start,&i,b),date9.);
      %put &date;
     %end;
   %mend date_loop;

   %date_loop(25DEC2022,25DEC2023)

Is it clear now. 

PaigeMiller
Diamond | Level 26

@Kirito1 wrote:

I want to do something like this but this is just normal a normal counting this code is doing. I am applying this code on a dataset I want it to update every time it reads the data.

For example: 

DATA B; SET A (where=('DATE_OF_APPROVAL'N GE '01DEC2022'D));

I have hard coded the date here but if I run this data on 02Dec2022 I don't want to specify the Date everytime I run the code.

I somehow want to use the below code to update 'DATE_OF_APPROVAL' everytime  I run this code.


 

I think what you want is the TODAY() function. The is no incrementing here.

 

DATA B; 
SET A (where=(DATE_OF_APPROVAL GE today()));
run;

 

--
Paige Miller

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1148 views
  • 3 likes
  • 2 in conversation