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

Hello Experts,

 

Do you know please a date format for this presetation of date : 20230213

 

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@SASdevAnneMarie wrote:

Sorry, I did not specify, I would like to get it as macro variable.


You need to provide more detail. Attempting to do some mind reading, maybe this is what you're looking for:

 

%let current_date = %sysfunc(today(), yymmddn8.);
%put &current_date.;

View solution in original post

7 REPLIES 7
Reeza
Super User

YYMMDDN8.

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p0iptsg6780kzfn1k5f0b8s7k7dq.ht...

 


@SASdevAnneMarie wrote:

Hello Experts,

 

Do you know please a date format for this presetation of date : 20230213

 

Thank you !


 

SASdevAnneMarie
Barite | Level 11

Sorry, I did not specify, I would like to get it as macro variable.

Reeza
Super User

@SASdevAnneMarie wrote:

Sorry, I did not specify, I would like to get it as macro variable.


You need to provide more detail. Attempting to do some mind reading, maybe this is what you're looking for:

 

%let current_date = %sysfunc(today(), yymmddn8.);
%put &current_date.;
SASdevAnneMarie
Barite | Level 11
Thank you !
ballardw
Super User

@SASdevAnneMarie wrote:

Sorry, I did not specify, I would like to get it as macro variable.


HOW do you expect to use that macro variable?

Quite often formatting a date into a value other than the native value is a poor choice as you can't use the text of a macro variable containing 20130213 to match the value of an actual date variable in a SAS data set.

 

A recent example of using a formatted macro variable date that fails because of the formatting: https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858470#M33...

 

PaigeMiller
Diamond | Level 26

@SASdevAnneMarie wrote:

Sorry, I did not specify, I would like to get it as macro variable.


Maxim 28: Macro variables should not be formatted. If you are going to perform arithmetic or Boolean logic on a macro variable, unformatted is best. The one exception: if you are going to use the macro variable in a label, title or filename, then it probably should be formatted.

--
Paige Miller
MayurJadhav
Quartz | Level 8

You can use following format to get date in 20230213 

yymmdd8.

Here is one simple example:

data _null_;
	format dt yymmddn8.;
	dt=today();
put dt=;
run;

output:

dt=20230213

 

Mayur Jadhav
BI Developer. Writer. Creative Educator.

SAS Blog → https://learnsascode.com
YouTube Channel: → https://www.youtube.com/@imayurj

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 880 views
  • 7 likes
  • 5 in conversation