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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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