I have a variable called Dia and saves a result with formed AAAAMMDD, the code is:
data _null_;
FECHA_HACE_DIAS = INTNX('MONTH', TODAY(), -1);
put 'FECHA_HACE_DIAS' FECHA_HACE_DIAS DATE9.;
A = TODAY();
put 'TODAY' A DATE9.;
y = YEAR(FECHA_HACE_DIAS);
m = MONTH(FECHA_HACE_DIAS);
d = DAY(FECHA_HACE_DIAS);
Dia = (y*10000 + m*100 + d);
put Dia;
The fourth parameter of INTNX allows you to align the data to the start, end or middle of the month. I would recommend doing the start and adding 15 to get the 16th day.
data _null_;
call symputx('Fetch_', put(intnx ('month',today(),-1, 'b') + 16 ,yymmddn8.) );
run;
%put Fetch_ = &Fetch_.;
@yesidgranadosv wrote:
Thank you Very Much, the truth if I work, but in this case I need to bring the 16th of each month
If you submit the following code it will generate a Macro variable "dia" that contains todays date in the format yyyy-mm-dd
%let dia=%sysfunc(today(), yymmdd10.);
%put &dia.;
@yesidgranadosv wrote:
In which way I can be more specific, your solution is not very clear
data _null_; call symputx('Fetch_', put(intnx ('month',today(),-1),yymmddn8.) ); run; %put Fetch_ = &Fetch_.;
The fourth parameter of INTNX allows you to align the data to the start, end or middle of the month. I would recommend doing the start and adding 15 to get the 16th day.
data _null_;
call symputx('Fetch_', put(intnx ('month',today(),-1, 'b') + 16 ,yymmddn8.) );
run;
%put Fetch_ = &Fetch_.;
@yesidgranadosv wrote:
Thank you Very Much, the truth if I work, but in this case I need to bring the 16th of each month
@yesidgranadosv wrote:
Thank you Very Much, the truth if I work, but in this case I need to bring the 16th of each month
Current month? Previous Month? Next month?
data _null_; date= mdy(month(today()),16, year(today())); call symputx('CurrentMonthFetch_', put(date,yymmddn8.) ); date= mdy(month(intnx('month',(today()),-1)),16, year(intnx('month',(today()),-1))); call symputx('PrevMonthFetch_', put(date,yymmddn8.) ); run; %put CurrentMonthFetch_ = &CurrentMonthFetch_.; %put PrevMonthFetch_ = &PrevMonthFetch_.;
The INTNX function does support a "middle" options such as
data _null_; date = intnx('month',today(),-1,'middle'); put date yymmddn8.; run;
Which may or may not be exactly what you want but may make more sense for February with the 14th as middle in most years, or 15 for months with 30 days.
If you really need to do this in a separate program, you have to save a permanent SAS data set. There is no way to transfer macro variables from one program to another.
Instead of using:
data _null_;
save the data set permanently:
data perm.something_to_hold_dia;
Then in your other program:
data _null_;
set perm.something_to_hold_dia;
call symputx('FECH_', dia);
run;
From my understanding of the problem, you need to create the 16th day of every month in yyyymmdd format and save it as macro var fech_
Then you need this macro var in another program. Basically the code calculates the last day of the previous month and then forwards it by 16 days.
So you save the data _null_ part in one program say day16.sas. Then call this program using %include in your other program where you will have access to Fech_ macrovar
/* save this part as day16.sas */
data _null_;
call symputx('fech_',compress(put((intnx('month',today(),-1,'e')+16),yymmdd10.),'-'));
run;
/* check macro var fech_ */
%put &fech_;
/* end of day16.sas */
/* In your other sas program call day16.sas */
/* %include "day16.sas"; */
/* Now you have access to &fech_ macro variable */
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.