DATA Step, Macro, Functions and more

arrays to change values to missing

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

arrays to change values to missing

array change (6) gpa, sat, satm, satv, act, toefl;
do i = 1 TO 6;
if change(i) = 0 then change(i) = 'missing';
end;
run;

 

want to make this array change each 0 value to missing but it isnt working...

any suggestions?

 


Accepted Solutions
Solution
‎03-27-2017 09:53 PM
Trusted Advisor
Posts: 1,128

Re: arrays to change values to missing

You are trying to update the numeric variables values to character value 'missing'. Hence it is not working i guess. Please try to create new character variables corresponding to the numeric variables and in them you could populate the missing value if the corresponding numeric values is zero in those variables.

could you please try this.

array change(6) gpa sat satm satv act toefl;
array changec(6)$10 gpac satc satmc satvc actc toeflc;
do i = 1 TO 6;
if change(i) = 0 then changec(i) = 'missing';
else changec(i) = put(change(i),best.);
end;
run;
Thanks,
Jag

View solution in original post


All Replies
Solution
‎03-27-2017 09:53 PM
Trusted Advisor
Posts: 1,128

Re: arrays to change values to missing

You are trying to update the numeric variables values to character value 'missing'. Hence it is not working i guess. Please try to create new character variables corresponding to the numeric variables and in them you could populate the missing value if the corresponding numeric values is zero in those variables.

could you please try this.

array change(6) gpa sat satm satv act toefl;
array changec(6)$10 gpac satc satmc satvc actc toeflc;
do i = 1 TO 6;
if change(i) = 0 then changec(i) = 'missing';
else changec(i) = put(change(i),best.);
end;
run;
Thanks,
Jag
Contributor
Posts: 25

Re: arrays to change values to missing

Perfect thank you.

If I wanted to keep it a numeric value could I use my old code and just use (missing) or something?

Trusted Advisor
Posts: 1,128

Re: arrays to change values to missing

Yes, if you want to make the zero to missing (.) then yes you could use your old code. But i think in the array you cannot separate the variables by comma as they will be considered as values , just separate the variables in array by space.

array change(6) gpa sat satm satv act toefl;
do i = 1 TO 6;
if change(i) = 0 then change(i) =.;
end;
Thanks,
Jag
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 226 views
  • 4 likes
  • 2 in conversation