Hello
%let mon1=2020;
%let mon2=2016;
/*I want to create another macro variable called vector that will get value 2020+2016
instead of define it manually %let vector=2020+2016;
I want that it will be defined automatically */
%let want = &mon1%str(+)&mon2;
%put &=want;
Hi @Ronein
Here is another approach, using the CATX() function, and the plus operator as the delimiter:
%let vector= %sysfunc(catx(+,&mon1.,&mon2.));
Best,
I am not sure I understand what your question means. Is it as simple runnng a %LET statement?
%let mon1=2020;
%let mon2=2016;
%let vector=&mon1+&mon2;
530 %put &=vector; VECTOR=2020+2016
Or did you want to assign a value to VECTOR in a way that its value will change without having to re-create it?
Something like:
data _null_;
call symputx('vector','&mon1+&mon2');
run;
535 %put %superq(vector); &mon1+&mon2 536 %put &=vector; VECTOR=2020+2016 537 %let mon1=2030; 538 %put &=mon1 &=mon2 &=vector; MON1=2030 MON2=2016 VECTOR=2030+2016
Not quite sure what you want. Is it just one variable with the text you displayed? then just do
%let vector=&mon1+&mon2;
Or do you want the calculated sum? then do
%let vector=%eval(&mon1+&mon2);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.