Hello,
I was wondering if someone can help me with a question working with array in data step. I was trying to drop all elements in an array after the reshape. Here is what i've tried and it gave error message that i can't refer the array this way in DROP statement. Is there a way to do it? Thanks in advance. - Xin
data tmp;
set tmp2;
array wide{*} _numeric_;
<other statement>
drop wide{*};
run;
This statement works IF you place it properly:
drop _numeric_;
It should appear immediately after the ARRAY statement.
In a DATA step, _numeric_ changes meaning as the DATA step creates more numeric variables. So place the DROP statement after ARRAY, but before creating additional variables.
If the purpose of this was to go from wide to narrow it likely is easier to KEEP the new variables. If there are lots of character variables to keep then use the _character_ variable list in the keep statement.
Yes, as you've point out, KEEP statement can be troublesome when there are lot of char varibles to keep. KEEP _character_ works well. Thanks a lot.
No, you can't do that as you have already figured out. The reason being non-executable statements such as 'Drop/Keep' works during the compiling stage, while Array statement works on execution stage. However, for the example you presented, you can do the following:
drop of _numeric_;
You don't need OF unless it is a variable name. OF is the special function syntax.
The drop _numeric_ will drop the new variables i've created and won't work.
Drop _numeric_ doesn't seem to be working. Here is a test:
data tmp;
set sashelp.class;
array wide[*] _numeric_;
do i = 1 to dim(wide);
put wide[i] =;
end;
drop _numeric_;
put wide[*] =;
run;
It worked on my computer. The three numberical variables are dropped in tmp as indicated by DROP statement. The last PUT statement will generate the three variables in log.
Yes TMP is OK.
This statement works IF you place it properly:
drop _numeric_;
It should appear immediately after the ARRAY statement.
In a DATA step, _numeric_ changes meaning as the DATA step creates more numeric variables. So place the DROP statement after ARRAY, but before creating additional variables.
Thanks! This is the solution!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.