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

Hi Everyone,

I want to create a macro variable that take the value of today date in the form yyyymmdd.

I can do it with my code below but I have to start with a dataset "mydata".

I thought that there should be a way to use _NULL_ data but I cant work it out.

Can you help me?

Thank you,

HC

 

*SOLUTION --------------------------------

data _NULL_;
format today yymmdd8.;
today=date(); 
ymd=year(today)*10000+month(today)*100+day(today);

   call symputx('next_month',put(ymd,10.));

run;

%put &next_month;

 


data TEMP; 		set Mydata;
format today yymmdd8.;
today=date(); 
ymd=year(today)*10000+month(today)*100+day(today);run;

	proc sql;
	select Max(ymd) into:todaydate
	from  TEMP;quit;

	%put &todaydate;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I don't really understand what your question is.

You do not need to have an input dataset to run a data step.

data _null_;
   x=today();
   next_month=intnx('month',x,1,'b');
   call symputx('next_month',put(next_month,yymmddn8.));
run;

View solution in original post

5 REPLIES 5
Reeza
Super User

Look up %SYSFUNC and note the two parameters.

 

%let today = %sysfunc(today(), yymmdd8.);

%put &today.;
hhchenfx
Barite | Level 11

Thank you for the suggestion.

 

I am more concern with manipulating the value a bit before passing it to macro variable.

 

HC

SuryaKiran
Meteorite | Level 14

hi,

 

Check out "CALL SYMPUT" which can pass the value to a macro variable with DATA _NULL_

Thanks,
Suryakiran
Tom
Super User Tom
Super User

I don't really understand what your question is.

You do not need to have an input dataset to run a data step.

data _null_;
   x=today();
   next_month=intnx('month',x,1,'b');
   call symputx('next_month',put(next_month,yymmddn8.));
run;
hhchenfx
Barite | Level 11
Thanks a lot.
HC

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 756 views
  • 0 likes
  • 4 in conversation