BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Xin
Fluorite | Level 6 Xin
Fluorite | Level 6

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; 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

11 REPLIES 11
ballardw
Super User

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.

Xin
Fluorite | Level 6 Xin
Fluorite | Level 6

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. 

Haikuo
Onyx | Level 15

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_; 

 

 

PGStats
Opal | Level 21
drop _numeric_;
but that will also drop any new numeric variable created in the datastep.
PG
data_null__
Jade | Level 19

You don't need OF unless it is a variable name.  OF is the special function syntax.

Xin
Fluorite | Level 6 Xin
Fluorite | Level 6

The drop _numeric_ will drop the new variables i've created and won't work. 

KachiM
Rhodochrosite | Level 12
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;
Xin
Fluorite | Level 6 Xin
Fluorite | Level 6

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. 

KachiM
Rhodochrosite | Level 12

Yes TMP is OK.

Astounding
PROC Star

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.

Xin
Fluorite | Level 6 Xin
Fluorite | Level 6

Thanks! This is the solution!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 5531 views
  • 4 likes
  • 7 in conversation