SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Dritan007
Fluorite | Level 6

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?

Dritan007_0-1604011462305.png

Data looks like this.

I have referenced all the variables with an array, however the format I don't want character.

2 REPLIES 2
Reeza
Super User
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;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1269 views
  • 0 likes
  • 3 in conversation