BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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 */
5 REPLIES 5
PaigeMiller
Diamond | Level 26
%let want = &mon1%str(+)&mon2;
%put &=want;
--
Paige Miller
ed_sas_member
Meteorite | Level 14

Hi @Ronein 

 

Here is another approach, using the CATX() function, and the plus operator as the delimiter:

%let vector= %sysfunc(catx(+,&mon1.,&mon2.));

Best,

smantha
Lapis Lazuli | Level 10
%let final_str=;
%do count=1 %to %eval(&n-1);
%let final_str=&final_str.%str(+)&&mon&count.;
%end;
%let final_str=&final_str.%str(+)&&mon&count.;
Tom
Super User Tom
Super User

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
s_lassen
Meteorite | Level 14

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);
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
  • 5 replies
  • 1361 views
  • 2 likes
  • 6 in conversation