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

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;

I Need to call the variable "Dia" in a variable macro called "%LET FECH_=" ... I call it the following way
"%LET FECH_ =&Dia;"
 
I NEED TO DO THIS TO CALL THE MACRO VARIABLE FECH_ IN ANOTHER PROGRAM SAS
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

View solution in original post

13 REPLIES 13
Reeza
Super User
It's hard to understand what you're asking here, but I think you're looking for CALL SYMPUT which you can use to create a macro variable from within a data step. Also, pretty sure there's SAS format you can use directly to get the data in the format needed.

Try this:

%let dia=%syfunc(today(), yymmdd10.);
%put &dia.;
yesidgranadosv
Obsidian | Level 7
In which way I can be more specific, your solution is not very clear
Reeza
Super User
Did you run it? What does it create?
yesidgranadosv
Obsidian | Level 7
I need format 20190411 not 2019-04-11
AMSAS
SAS Super FREQ

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

 

 

Reeza
Super User
ah...I got the format wrong. And try yymmddn10 or yymmddd10 for the one with no dashes.
ballardw
Super User

@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_.;
yesidgranadosv
Obsidian | Level 7
Thank you Very Much, the truth if I work, but in this case I need to bring the 16th of each month
Reeza
Super User

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

 

Reeza
Super User
Or that entire line could be in a %LET as I sort of showed earlier, but with some more nesting of %SYSFUNC().
ballardw
Super User

@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.

Astounding
PROC Star

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;

ghosh
Barite | Level 11

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 */

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 13 replies
  • 2857 views
  • 3 likes
  • 6 in conversation