Is there a way to compute and store rather than just store a string to be resolved later?
%let measureSummed = &measureTy || _sum;
I would like measureSummed to store the value of &measureTy + _sum instead of
&measureTy || _sum.
If measureTy is a macro variable, this is easy:
%let measureSummed = &measureTy._sum;
(It gets a little more complicated if &MeasureTy contains an embedded blank.)
But your description makes it sound like measureTy is a DATA step variable. In that case, SAS can do what you want, but the process needs to be split into two steps. The reason is that SAS needs to know all the variables that a DATA step will process before it runs the DATA step. But running the DATA step is required to examine the value of measureTy. So here is a possibility:
data _null_;
set have;
call symputx('measureSummed', strip(measureTy) || '_sum');
run;
Or if measureTy contains an embedded blank that needs to be converted to an underscore:
data _null_;
set have;
call symputx('measureSummed', translate(strip(measureTy), '_', ' ') || '_sum');
run;
Then later in the program you can refer to &measureSummed.
Are we getting close?
In macro language, _sum is just 4 characters. It is not something that can be added. There are other variations that you might be looking for, such as:
%let measureSummed = &measureTy._sum;
%let measureSummed = %eval(&measureTy + &_sum);
It's possible you can do what you want to, but it's not 100% clear what you are trying to get from this.
Good luck.
%let measureSummed = &measureTy || &_sum;
%let measureSummed=%sysevalf(%sysfunc(translate(&measureSummed,+,||)));
%put &measureSummed;
I’m researching a few of the keywords used in your example.
To clarify I have a column that is dynamically generated and SAS appends the text _sum to it. measureTy is the first half of the column name. _sum is the second half. Note _sum is not a variable. An example of the full created column name is students_enrolled_sum. Where measureTy is students enrolled and _sum needs to be appended.
When I use:
data enrollment; set enrollment;
rename &measureSummed = n;
run;
I can’t have two strings in the rename &measureSummed = n;
There is the sashelp metadata files which contain the information about all tables/columns. I find using that is easier than fiddling around with lists of ampersands, quoting etc.:
data _null_;
set sashelp.vcolumn (where=(libname="WORK" and memname="XYZ" and substr(strip(reverse(NAME)),1,3)="MUS"));
call symputx('YOUR_VAR',name);
run;
Or just generate the necessary code from a call execute. Or alternatively keep a running dataset with the variable name plus _sum, and use that.
If measureTy is a macro variable, this is easy:
%let measureSummed = &measureTy._sum;
(It gets a little more complicated if &MeasureTy contains an embedded blank.)
But your description makes it sound like measureTy is a DATA step variable. In that case, SAS can do what you want, but the process needs to be split into two steps. The reason is that SAS needs to know all the variables that a DATA step will process before it runs the DATA step. But running the DATA step is required to examine the value of measureTy. So here is a possibility:
data _null_;
set have;
call symputx('measureSummed', strip(measureTy) || '_sum');
run;
Or if measureTy contains an embedded blank that needs to be converted to an underscore:
data _null_;
set have;
call symputx('measureSummed', translate(strip(measureTy), '_', ' ') || '_sum');
run;
Then later in the program you can refer to &measureSummed.
Are we getting close?
This solved it:
%let measureSummed = &measureTy._sum;
measureTy is a marco variable that I concatenated with the text _sum in the datastep.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.