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 need the date in format
 
I need a variable that saves me the value of the current year and month with the day 2 of each month
 
AAAAMMDDD
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data _null_;
call symputx('Fetch_COM', put(intnx ('month',today(),0, 'b') + 1 ,yymmddn8.) );
run;

%put &Fetch_COM;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

We all have needs.

 

I have needs too.

 

I need you to tell me the names of the variables that you have to work with, and give a couple of examples of the values they contain and the result that you would like.

yesidgranadosv
Obsidian | Level 7

data _null_;
call symputx('Fetch_COM', put(intnx ('month',today(),-2, 'b') + 27 ,yymmddn8.) );
run;

I HAVE THE VARIABLE "Fetch COM" 
SHE GIVES ME AS a RESULT 20190228 
I NEED a VARIABLE TO DELIVER ME AS a RESULT 20190402 
THE CURRENT DATE WITH DAY 2

novinosrin
Tourmaline | Level 20
data _null_;
call symputx('Fetch_COM', put(intnx ('month',today(),0, 'b') + 1 ,yymmddn8.) );
run;

%put &Fetch_COM;
Reeza
Super User

@yesidgranadosv wrote:

data _null_;
call symputx('Fetch_COM', put(intnx ('month',today(),-2, 'b') + 27 ,yymmddn8.) );
run;

I HAVE THE VARIABLE "Fetch COM" 
SHE GIVES ME AS a RESULT 20190228 
I NEED a VARIABLE TO DELIVER ME AS a RESULT 20190402 
THE CURRENT DATE WITH DAY 2


I think this means you didn't understand the code provided previously. 

 

27 puts the date at 27+1 =28 days. If you want day 2, change the 27 accordingly to get the date you want. 

Reeza
Super User

@yesidgranadosv wrote:

data _null_;
call symputx('Fetch_COM', put(intnx ('month',today(),-2, 'b') + 27 ,yymmddn8.) );
run;

I HAVE THE VARIABLE "Fetch COM" 
SHE GIVES ME AS a RESULT 20190228 
I NEED a VARIABLE TO DELIVER ME AS a RESULT 20190402 
THE CURRENT DATE WITH DAY 2


That's not quite correct and please don't type in all upper case, it's the equivalent of yelling. 

 

You're creating a macro variable, named Fetch_CON, that is the second day of the current year and month. You do not have a variable with that value nor are you using data from a data set.

 

TODAY() returns the current date

INTNX() moves that date to the beginning of the month, since the first parameter is month and the last paramter is 'b' for beginning of the month. 

+1/27 adds the number of days to the month as needed.

YYMMDDN formats the date to appear in your desired format, although it's still a SAS date underneath. If you're planning to work more with dates and macro variables, I highly recommend reading the date and time tutorials here, you'll save yourself a lot of time:

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

 

or more specifically, this PDF file attached.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7028 views
  • 2 likes
  • 4 in conversation