BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Mathis91
Calcite | Level 5

Hello, I want to drop a variable in a dataset which came from a transpose.

The difficulty here is the number of variables to drop : it can change following the number of columns at the end of the transpose.

 

I've tried this : 

 

data datasetname;
set datasetname;
array date[&Dimension_tbl.];

do i=1 to &Dimension_tbl.;
drop date{i};
end;
run;

 

I don't understand why it doesn't work. Of course, the &Dimension_tbl. is defined earlier.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. Then you can use the logic by @LinusH or simply do

 

drop date:;

 

Which will drop all variables prefixed with 'date' .

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

A few things. 

 

  1. The Drop Statement is a complie-time only statement. Meaning that it is not considered during execution of the data step. Therefore it cannot be called in conditional logic.
  2. What does &Dimension_tbl. contain?
  3. Since your data is from a Transpose, I assume that the variables (columns) you want to drop share a common prefix, correct?

 

Mathis91
Calcite | Level 5
Thanks for your reply.

&Dimension_tbl. contains the number of columns created during the transpose, it's the number of date variables

And yes, the variables that I want to drop share a common prefix, which is "date". The suffix is between 1 and &Dimension_tbl.
PeterClemmensen
Tourmaline | Level 20

Ok. Then you can use the logic by @LinusH or simply do

 

drop date:;

 

Which will drop all variables prefixed with 'date' .

Mathis91
Calcite | Level 5
Thanks a lot, I didn't know about this feature !
LinusH
Tourmaline | Level 20

No, but you can use a variable range for this:

 

drop date1-date&Dimension_tbl.;

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0wphcpsfgx6o7n1sjtqzizp1n39.htm#:~:tex...

 

Data never sleeps
Mathis91
Calcite | Level 5
Thanks but it didn't work.
In the documentation I didn't see an example with a macrovariable, I don't know if it's me who doesn't understand how to use it
Tom
Super User Tom
Super User

@LinusH wrote:

No, but you can use a variable range for this:

 

drop date1-date&Dimension_tbl.;

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0wphcpsfgx6o7n1sjtqzizp1n39.htm#:~:tex...

 


This is the better answer than use date: variable list.  If you drop using the date prefix it might drop other variables that were not intended.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 627 views
  • 3 likes
  • 4 in conversation