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.
@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;
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.
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."
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.
@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;
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!
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.