DATA Step, Macro, Functions and more

Create a macro value // passing value to macro variable

Accepted Solution Solved
Reply
Super Contributor
Posts: 503
Accepted Solution

Create a macro value // passing value to macro variable

[ Edited ]

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;

 


Accepted Solutions
Solution
‎11-22-2017 06:14 PM
Super User
Super User
Posts: 7,932

Re: Create a macro value // passing value to macro variable

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


All Replies
Super User
Posts: 23,249

Re: Create a macro value // passing value to macro variable

Look up %SYSFUNC and note the two parameters.

 

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

%put &today.;
Super Contributor
Posts: 503

Re: Create a macro value // passing value to macro variable

Thank you for the suggestion.

 

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

 

HC

Valued Guide
Posts: 559

Re: Create a macro value // passing value to macro variable

hi,

 

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

Thanks,
Suryakiran
Solution
‎11-22-2017 06:14 PM
Super User
Super User
Posts: 7,932

Re: Create a macro value // passing value to macro variable

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;
Super Contributor
Posts: 503

Re: Create a macro value // passing value to macro variable

Thanks a lot.
HC
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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