Hi All,
I need to take a '.' out of 44 variables: var_1-var_44 and would like to do this with an array. The following code is not working. Can you help me troubleshoot?
Data...
length vrn $8.;
array varnew (*) var_1-var_44;
do i=1 to dim(varnew);
vrn=compress(trim(vrn), '.');
end;
drop i;
....
run;
Thanks.
You need to use VARNEW(I) to reference the current variable instead of VM.
Personally I would use DO OVER, but SAS is trying to remove that functionality.
array varnew var_1-var_44 ;
do over varnew;
varnew=compress(varnew,'.');
end;
You need to use VARNEW(I) to reference the current variable instead of VM.
Personally I would use DO OVER, but SAS is trying to remove that functionality.
array varnew var_1-var_44 ;
do over varnew;
varnew=compress(varnew,'.');
end;
Thanks Tom that worked. However, if SAS is getting rid of DO OVER, what other options are there? When I reference varnew in the compress function without the DO OVER, I get an error that the varnew var can't be referenced here. Example:
array varnew (*) var_1-var_44;
do i=1 to dim(varnew);
vrn=compress(trim(varnew), '.');
end;
drop i;
If using the explicit array step, the i= 1 to dim() then you have to use the Explicit array reference varnew.
If you want to use explicit array references then you do have to actually be explicit in your references, so make sure the include the index value when you use the array name in a statement.
Plus you need to write the result back to the same variable if you want it to have any effect.
Note that you really don't need the (*) as SAS knows that you have listed the variables and can count them itself.
And the TRIM() function is doing nothing in this context.
array varnew var_1-var_44;
do i=1 to dim(varnew);
varnew(i)=compress(varnew(i), '.');
end;
drop i;
Just on a hunch ... is it possible that these variables are numeric rather than character?
Bingo Astounding
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.