Search code examples
macrossasdo-loops

Change of a macro variable in a DO loop


Im using the following loop to generate the sums of some columns using a class statement:

%macro do_mean;

%do i = 50 %to 100;

%let string1 = %eval(100-&i);

**%if string1 = 5 %then %let string1 = "05";**

%if &i = 95 or &i = 90 or &i = 80 or &i = 70 or &i = 60 or &i = 50 %then %do;

proc means data = risiko.risiko_Haus sum nway noprint; 

var  HA_Max_Neg HA_Max_Pers;

class C_ze_Risiko_&i._2014_&string1._2015;

output out=test_ze_Risiko_&i._2014_&string1._2015 (drop=_type_ _freq_)

sum=C_Risiko_&i._2014_05_2015_Max_Neg C_Risiko_&string1._2014_05_2015_Max_Per;

run;

%end;

%end;

%mend do_mean;

%do_mean;here

The names columns I want to use as a class are "C_ze_Risiko_50_2014_50_2015" "C_ze_Risiko_60_2014_40_2015" and so on.

Unfortunately the code produces "C_ZE_RISIKO_95_2014_5_2015" but I need "C_ZE_RISIKO_95_2014_05_2015" instead. I marked the line where I tried to change this. Unfortunately this doesnt work. Can somebody tell me why and suggest a solution?

Thanks in advance.


Solution

  • An alternative to Gregory's answer is to use putn and the z2. format, e.g.

    %LET STRING1 = %SYSFUNC(putn(%EVAL(100-&I),z2.)) ;