SAS users.
I have a dataset that contains sequentially named variables called telco_enq083, telco_enq084.
I am trying to write a macro that works out the horizontal sum of these variables for each observation.
Of course, test dataset is an extract of a much bigger dataset and I have more sequential variables(Full dataset has columns that look like -
telco_enq083, telco_enq084, telco_enq091, telco_enq092, telco_enq093, telco_enq094, telco_enq101... etc)
How would you modify the below macro to make it work? I have tried %SYSFUNC and it does not work and SAS says it cannot read the argument of the SUM function...
%LET a=telco_enq;
%MACRO Distribution(var);
DATA test2;
SET test;
%LET Total=SUM(of &var:);
RUN;
%MEND;
%Distribution(a);
I'm not sure why you would want to put this in a macro, or the result in a macro variable, but I think that the following does what you describe:
data test;
input telco_enq85-telco_enq90;
cards;
1 1 1 1 1 1
;
%global total;
%MACRO Distribution(var);
DATA test2;
SET test;
Total=SUM(of &var.:);
call symput('total',total);
RUN;
%MEND;
%Distribution(telco_enq)
%put &total.;
I'm not sure why you would want to put this in a macro, or the result in a macro variable, but I think that the following does what you describe:
data test;
input telco_enq85-telco_enq90;
cards;
1 1 1 1 1 1
;
%global total;
%MACRO Distribution(var);
DATA test2;
SET test;
Total=SUM(of &var.:);
call symput('total',total);
RUN;
%MEND;
%Distribution(telco_enq)
%put &total.;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.