Hello,
The macro below is very useful when you run it after a proc report because it replaces the meaningless _Ci_ with the variable labels.
However, it bugs with the following example because the numeric variables have the same label ! The Year is no longer in the output file. Would it be possible to modify the macro and add a suffix (and get for example: REGION_A_1, REGION_B_1, etc.) so the macro can always run;
data F1;
label x='REGION_A' y='REGION_B'; FORMAT DEP $8.;
DEP="SUMMER" ; x=200 ; Y=300; Year=2016; output;
DEP="SUMMER"; x=100; Y=40;Year=2015; output;
DEP="SUMMER"; x=800; Y=600; Year=2014; output;
DEP="WINTER" ; x=500 ; Y=500; Year=2016; output;
DEP="WINTER"; x=140; Y=140;Year=2015; output;
DEP="WINTER"; x=80; Y=60; Year=2014; output; run;
proc report data=F1 nowd out=F2(drop=_BREAK_);
column DEP year, (X Y);
define dep / group;
define year / across; run;
%renlabel(F2) does not work
****************************************************************************
%macro renlabel(dsn);
%let dsid=%sysfunc(open(&dsn));
%let cnt=%sysfunc(attrn(&dsid,nvars));
%do i= 1 %to &cnt;
%let var&i=%sysfunc(varname(&dsid,&i));
%let lab&i=%sysfunc(varlabel(&dsid,&i));
%if &&lab&i = %then %let lab&i=&&var&i;
%end;
%let rc=%sysfunc(close(&dsid));
proc datasets;
modify &dsn;
rename
%do j = 1 %to &cnt;
%if &&var&j ne &&lab&j %then %do;
&&var&j=&&lab&j
%end;
%end;;
quit;
run;
%mend renlabel;
... View more