/**********************************************************************/ /* Method 1 */ proc sort data=node1; by id malig_no node_cod site_loc; data temp; set node1; by id malig_no node_cod site_loc; retain site; if first.node_cod then site=''; site=trim(left(site))||site_loc; if site not in ('', 'L', 'M', 'R', 'LR') then put id= site=; if last.node_cod then output; drop site_loc; rename site=site_loc; proc transpose data=temp out=goal1 (drop=_NAME_); by id malig_no; id node_cod; var site_loc; proc print data=goal1; where id in ('1','2'); run; /**********************************************************************/ /* Method 2 */ data node2; set vwlib.node; array missing {*} _CHARACTER_; do i=1 to dim(missing); if missing{i}='' then missing{i}='Z'; end; proc sort data=node2; by id node_cod site_loc; proc print data=node2; where id in ('1','2'); run; /**********************************************************************/ proc transpose data=node2 out=nodet prefix=var; var node_cod--bulky; by id malig_no; run; proc print data=nodet; where id in ('1','2'); run; /**********************************************************************/ %macro r (a, name, new); data &a; set nodet; by id malig_no; %local i; %do i=1 %to 3; if _NAME_="&name" then do; &new&i=var&i; if &i=1 and &new&i='' then delete; end; else delete; end; drop _NAME_ var1-var3; run; %mend r; %r(b, NODE_COD, node); %r(c, SITE_LOC, site); %r(d, NODE_SIZ, size); %r(e, BULKY , bulk); /**********************************************************************/ proc print data=b; where id in ('1','2'); proc print data=c; where id in ('1','2'); proc print data=d; where id in ('1','2'); proc print data=e; where id in ('1','2'); run; /**********************************************************************/ data all; merge b c d e; by id malig_no; array missing {*} node1-node3 site1-site3 size1-size3 bulk1-bulk3; do i=1 to dim(missing); if missing{i}='Z' then missing{i}=''; end; proc print data=all; where id in ('1','2'); run; /**********************************************************************/ array valid {3} node1-node3; a='/' b='_'; do i=1 to 3; if index(valid{i},a) ne 0 then valid{i}=translate(valid{i}, b, a); end; /**********************************************************************/ prev_n=' '; prev_s=' '; array node{3} node1-node3; array site{3} site1-site3; array s{3} s1-s3; do i=1 to 3; s{i}=site{i}; if node{i}=prev_n then s{i}=trim(prev_s)||site{i}; if s{i} not in ('', 'L', 'M', 'R', 'LR') then put id= s{i}=; prev_n=node{i}; prev_s=site{i}; end; proc print; where id in ('1','2'); var id node1-node3 s1-s3; run; /**********************************************************************/ %macro assign (n, site); %local i; %let z=sz; %let b=bl; %do i=1 %to 3; if node&i="&n" then do; &n=s&i; if site&i="&site" then do; &site&n&z=size&i; &site&n&b=bulk&i; end; end; %end; %mend assign; %assign (AXIL,); %assign (AXIL, L); %assign (AXIL, R); %assign (GAST,); %assign (GAST, M); %assign (INGU,); %assign (INGU, L); %assign (INGU, R); drop i prev_n prev_s node1-node3 site1-site3 s1-s3 size1-size3 bulk1-bulk3; proc print; where id in ('1','2'); run; /**********************************************************************/