Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create several variables in do loop by concatenating already existing

Status
Not open for further replies.

matthijs1

Technical User
Oct 17, 2011
1
BE
Hello,

The problem I have is the following: In my program, I want to create a new variable when a current variable has a missing value. This is what I already have:

data basetabel_imputed;
set basetablenum;
array wit{*} _numeric_;
do i=1 to dim(wit);
if wit(i)=. then do;
wit(i)= symget(vname(wit(i));
end;
end;
drop i;
run;

I read in the variables, make an array of the numeric ones and then, for every numeric variable, I change the missing value by the median of that variable. Now, in the second do loop, I want to create a new variable, that has the same name as the variable currently accessed by the do loop, except that I want to add the suffix mv to it. Then I want this new variable to take the value 1. What I want is in fact a statement that does:

vname(wit(i))||mv = 1;
(but his doensn't work because one cannot create a new variable name like that).

Matthijs



 
You can try this:

data basetabel_imputed (drop=varname val row n) varnames (keep= varname val row);

set basetabel (obs=50 ) end=last;
array wit{*} _numeric_;
n + 1;
do i=1 to dim(wit);
if wit(i)=. then do;
varname = 'mv'||vname(wit(i));
val = 1;
row = n;
output varnames;
end;
end;
*output basetabel_imputed;
if last then do;
call execute('proc transpose data=varnames out=varnames2 (keep=mv:);var val;id varname;by row;run;');
do i=1 to n;
set basetabel point=i;
set varnames2 point=i;
output basetabel_imputed;
end;
end;
drop i;
run;

BIGuidance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top