×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

create several variables in do loop by concatenating already existing

create several variables in do loop by concatenating already existing

create several variables in do loop by concatenating already existing

(OP)
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



 

RE: create several variables in do loop by concatenating already existing

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
www.biguidance.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close