data have; input @1 a @3 b $10. @14 c $5. @20 d; cards; 1 2654321234 33456 4 ; %macro vars(dsn); %let list=; %let type=; %let dsid=%sysfunc(open(&dsn)); %let cnt=%sysfunc(attrn(&dsid,nvars)); %do i = 1 %to &cnt; %let list=&list %sysfunc(varname(&dsid,&i)); %let type=&type %sysfunc(vartype(&dsid,&i)); %end; %let rc=%sysfunc(close(&dsid)); data want(drop= %do i = 1 %to &cnt; %let temp=%scan(&list,&i); _&temp %end;); set &dsn(rename=( %do i = 1 %to &cnt; %let temp=%scan(&list,&i); &temp=_&temp %end;)); %do j = 1 %to &cnt; %let temp=%scan(&list,&j); /** Change C to N for numeric to character conversion **/ %if %scan(&type,&j) = N %then %do; /** Also change INPUT to PUT for numeric to character **/ &temp=PUT(_&temp,8.); %end; %else %do; &temp=_&temp; %end; %end; run; %mend vars; %vars(one) proc contents data=have; run; proc contents data=want; run; Have Want
... View more