BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
willy0625
Calcite | Level 5

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);

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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.;

View solution in original post

1 REPLY 1
art297
Opal | Level 21

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.;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 6230 views
  • 0 likes
  • 2 in conversation