Hello everyone, I have this code that works in changing the length of a variable. I am doing this beacuse i want to combine datasets to one, so the variables should have same length.
i am going to stack 9 files (yr1, yr2, ...yr9) and i want them all to have the same character length for 3 types of variables (dupersid, duig, condidx). I can only do for each variable at a time. Is there a way I can circumvent this so that all the length of the 3 variables will adjusted in one data step? Thank you
/***********************************************************************
- change the 8-character dupersid to 10-character dupersid
by adding the panel number to DUPERSIDs of panel 22 year 2017
and panels 1-21 in the PLVE file
- there is no year variable in the PLVE file
- implement this change by using the LENGTH and STRIP functions as folows
*************************************************************************/
data vsfile ;
length dupersid $10;
set new.h36u20 (rename=(dupersid=t_dupersid));
if length(strip(t_dupersid))=8 then
dupersid=cats(put(panel,z2.), t_dupersid);
else dupersid = t_dupersid;
drop t_dupersid;
run;
/***this is what i try to do but does not work**/
data XX;
length dupersid $10 duid $7 condidx $13;
set meps.YRM2011 (rename=(dupersid=t_dupersid));
if length(strip(t_dupersid))=8 then
dupersid=cats(put(panel,z2.), t_dupersid);
else dupersid = t_dupersid;
drop t_dupersid;
(rename=(duid=t_duid));
if length(strip(t_duid))=8 then
duid=cats(put(panel,z2.), t_duid);
else duid = t_duid;
drop t_duid;
(rename=(condidx=t_condidx));
if length(strip(t_condidx))=8 then
condidx=cats(put(panel,z2.), t_condidx);
else condidx = t_condidx;
drop t_condidx;
run;
Log
127 data XX;
128 length dupersid $10 duid $7 condidx $13;
129 set meps.YRM2011 (rename=(dupersid=t_dupersid));
130 if length(strip(t_dupersid))=8 then
131 dupersid=cats(put(panel,z2.), t_dupersid);
132 else dupersid = t_dupersid;
133 drop t_dupersid;
134
135 (rename=(duid=t_duid));
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
136 if length(strip(t_duid))=8 then
137 duid=cats(put(panel,z2.), t_duid);
138 else duid = t_duid;
139 drop t_duid;
140
141 (rename=(condidx=t_condidx));
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
142 if length(strip(t_condidx))=8 then
143 condidx=cats(put(panel,z2.), t_condidx);
144 else condidx = t_condidx;
145 drop t_condidx;
146 run;
... View more