- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-29-2020 06:46 PM
(1268 views)
Hello guys.
I have this array with character variables, even though values are all 0 and 1 or ' ' for missing value. I need these variables in a numeric format but I am having a hard time. Is there a way to do so without creating another array?
Data looks like this.
I have referenced all the variables with an array, however the format I don't want character.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You must have a second array, because you cannot change the type of a variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How did you import or create the data? Can you change it in a prior step - this is definitely possible if you imported the data from a text file.
If you created it, you can back up and modify your code. Otherwise, duplicate arrays are your best bet and pretty straightforward though definitely an annoyance.
data want;
set have;
array _orig(*) $2 <list of old vars>; *can be automated somewhat;
array _new(*) <list of new_vars>; *can be automated somewhat;
do i=1 to dim(_orig);
if not missing(_orig(i)) then _new(i) = input(orig(i), 8.);
end;
drop <list of old vars>;
run;
If you created it, you can back up and modify your code. Otherwise, duplicate arrays are your best bet and pretty straightforward though definitely an annoyance.
data want;
set have;
array _orig(*) $2 <list of old vars>; *can be automated somewhat;
array _new(*) <list of new_vars>; *can be automated somewhat;
do i=1 to dim(_orig);
if not missing(_orig(i)) then _new(i) = input(orig(i), 8.);
end;
drop <list of old vars>;
run;