Hello @gamotte , Thank you for you answer. I think I'm starting to understand how the macro works. I took a code I had in which I repeated several times the same instruction but with different variables. I used the macro language to "reduce" the code as you can see below: data test_hierarchie ;
set mdv.hierarchie ;
_COD_ETB = input(COD_ETB, $15.);
_COD_EDS_EXTR_NIV1 = input(COD_EDS_EXTR_NIV1, $15.);
_COD_EDS_EXTR_NIV2 = input(COD_EDS_EXTR_NIV2, $15.);
_COD_EDS_EXTR_NIV3 = input(COD_EDS_EXTR_NIV3, $15.);
_COD_EDS_EXTR_NIV4 = input(COD_EDS_EXTR_NIV4, $15.);
_COD_EDS_EXTR_NIV5 = input(COD_EDS_EXTR_NIV5, $15.);
_COD_EDS_EXTR_NIV6 = input(COD_EDS_EXTR_NIV6, $15.);
_COD_EDS_EXTR_NIV7 = input(COD_EDS_EXTR_NIV7, $15.);
_COD_EDS_EXTR_NIV8 = input(COD_EDS_EXTR_NIV8, $15.);
_LIB_ETB = put(LIB_ETB, $50.);
_LIB_EDS_INT_NIV1 = put(LIB_EDS_INT_NIV1,$50.) ;
_LIB_EDS_INT_NIV2 = put(LIB_EDS_INT_NIV2,$50.) ;
_LIB_EDS_INT_NIV3 = put(LIB_EDS_INT_NIV3,$50.) ;
_LIB_EDS_INT_NIV4 = put(LIB_EDS_INT_NIV4,$50.) ;
_LIB_EDS_INT_NIV5 = put(LIB_EDS_INT_NIV5,$50.) ;
_LIB_EDS_INT_NIV6 = put(LIB_EDS_INT_NIV6,$50.) ;
_LIB_EDS_INT_NIV7 = put(LIB_EDS_INT_NIV7,$50.) ;
_LIB_EDS_INT_NIV8 = put(LIB_EDS_INT_NIV8,$50.) ;
run ;
Proc sql ;
create table test_hierarchie1 as
select
NBNIV,
CleEDS,
_LIB_ETB as lib_plus_grd,
_LIB_EDS_INT_NIV1 as lniv1,
_LIB_EDS_INT_NIV2 as lniv2,
_LIB_EDS_INT_NIV3 as lniv3,
_LIB_EDS_INT_NIV4 as lniv4,
_LIB_EDS_INT_NIV5 as lniv5,
_LIB_EDS_INT_NIV6 as lniv6,
_LIB_EDS_INT_NIV7 as lniv7,
_LIB_EDS_INT_NIV8 as lniv8,
_COD_ETB as niveau_plus_grd,
_COD_EDS_EXTR_NIV1 as cniv1,
_COD_EDS_EXTR_NIV2 as cniv2,
_COD_EDS_EXTR_NIV3 as cniv3,
_COD_EDS_EXTR_NIV4 as cniv4,
_COD_EDS_EXTR_NIV5 as cniv5,
_COD_EDS_EXTR_NIV6 as cniv6,
_COD_EDS_EXTR_NIV7 as cniv7,
_COD_EDS_EXTR_NIV8 as cniv8
from test_hierarchie ;
run ; (These two codes are in a macro.) I have transformed these two codes like this : Data test (keep = nbniv cleEDS lib_plus_grd lniv: niveau_plus_grd cniv:);
Set mdv.hierarchie ;
%do i = 1 %to 8 ;
_COD_EDS_EXTR_NIV&i = input(COD_EDS_EXTR_NIV&i, $15.);
_LIB_EDS_INT_NIV&i = put(LIB_EDS_INT_NIV&i,$50.) ;
rename _LIB_EDS_INT_NIV&i = lniv&i ;
rename _COD_EDS_EXTR_NIV&i = cniv&i ;
%end ;
_COD_ETB = input(COD_ETB, $15.);
_LIB_ETB = put(LIB_ETB, $50.);
rename _COD_ETB = niveau_plus_grd ;
rename _LIB_ETB = lib_plus_grd ;
run ;
data test1 ;
retain nbniv cleEDS lib_plus_grd lniv1-lniv8 niveau_plus_grd cniv1-cniv8 ;
set test ;
run ; Is this a good use of macro ? (I don't ask you to rewrite my code but just tell if the use of macro language is appropriate here).
... View more