Help using Base SAS procedures

How to use SUM(of var1-varn) in macro

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

How to use SUM(of var1-varn) in macro

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 &varSmiley Happy;

     RUN;

%MEND;

%Distribution(a);

Attachment

Accepted Solutions
Solution
‎09-27-2011 12:20 AM
PROC Star
Posts: 7,356

How to use SUM(of var1-varn) in macro

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

    call symput('total',total);

  RUN;

%MEND;

%Distribution(telco_enq)

%put &total.;

View solution in original post


All Replies
Solution
‎09-27-2011 12:20 AM
PROC Star
Posts: 7,356

How to use SUM(of var1-varn) in macro

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

    call symput('total',total);

  RUN;

%MEND;

%Distribution(telco_enq)

%put &total.;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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