So if this is for a report, why are we talking about this code at all:
proc transpose data=have out=want;
by id id2;
var xyz;
idlabel monthvar;
run;
proc report data=want;
columns _name_ var:;
run;
The proc transpose creates a transposed dataset with xyz going across, with each variable named varX where X is an incremental number and month as label, e.g.
ID ID2 VAR1 (Jan16) VAR2 (Mar16)....
In this way you don't need the list of months, and can use shortcuts like var: i.e. all variables with var prefix. Much simpler.
"However, %nrstr also doesn't solve this" - this doesn't really tell me anything. Here is a working version:
%macro tmp (a=);
%local tmp;
%let tmp=%sysfunc(tranwrd(&a.,|,%str(,)));
%put &tmp.;
%mend tmp;
%let list=abc|def|ghi;
%tmp(a=%str(&list.));
... View more