The SAS Output Delivery System and reporting techniques

Abour keep and drop option

Reply
N/A
Posts: 0

Abour keep and drop option

Whether we can use array in drop or keep option?
N/A
Posts: 0

Re: Abour keep and drop option

Posted in reply to deleted_user
Yep, would be nice - doesn't work though. Lets see what SAS comments are.

If you're having problem with long variable lists and you know the order in your file (variable number) you can specify firstVar--lastVar which will select all variables in between the two specified.
SAS Employee
Posts: 39

Re: Abour keep and drop option

Posted in reply to deleted_user
Ashutosh, let me show what SAS can do then we'll discuss what it can't.

The DROP= data set option and DROP statement support variable lists to drop a set of variables. For instance, to drop all the variables from an output data set that begin with the prefix "X" one would code:

[pre]
DATA OUT( DROP=X: );
[/pre]

To drop the variables X1 through X10, one would code:

[pre]
DATA OUT( DROP=X1-X10 );
[/pre]

Variable lists work in many situations where a programmer would like to drop an array of variables.

The situation where variable lists break down is when an array of variables do not have a common prefix. As in:

[pre]
ARRAY A
  • X Y Z;
    [/pre]

    In this case using DROP=X--Z may drop X, Y, and Z. I say may because if the variables aren't ordering in the PDV as X, then Y, then Z, the variables you think you're dropping will not be dropped. I'd rather code DROP=X Y Z than use X--Z because maintaining a variable ordering in the PDV can be tricky and obfuscate the code.

    If you have a situation where variable lists don't work well, a workaround is to place the array variables in a macro variable. As in this code:

    [pre]
    %let ArrayVars = x y z;
    data out(drop=&ArrayVars.);
    array a
  • &ArrayVars.;
    set in;
    run;
    [/pre]

    This program will create an array consisting of the variables X, Y, and Z and will drop them from the output data set.

    The reason arrays aren't supported with the DROP= or KEEP= option is that the options are not processed by the DATA step. Rather, they are processed by the engine that is used to read or write the data set. The engine is aware of the variables to be read or written, so it can drop or keep them. The engine is not aware of DATA step arrays, so it would not recognize a name as an array. The separation between the DATA step and the engine is what keeps DROP= or KEEP= from handling arrays.

    -- Jason Secosky, SAS R&D / DATA Step
  • N/A
    Posts: 0

    Re: Abour keep and drop option

    Posted in reply to deleted_user
    Ashutosh and Jason,

    I have just started with a system that has many, many fields - Ashutosh you might be in the same boat. Correct me if I'm wrong here.

    We don't have a situation of X Y Z but rather 100's of fields, which makes programs lengthy and difficult to manage. Arrays make short work of repeated calculations and macro variables containing the variable names also shortcut a lot of it. But whatever route you take, you still end up with these long, unwieldy lists somewhere.

    I'm taking the attitude of more rows less columns - trying the reduce the variable lists to categories in columns. Use of proc transpose can interchange between the tables. Taking this different approach makes programming much easier and shorter - have you tried thinking in this way? I've also returned a 75% space saving with this method - this is the business motivation of taking this route. Its often difficult justifying code changes without any obvious end-result.

    Jason your thoughts?
    SAS Employee
    Posts: 39

    Re: Abour keep and drop option

    Posted in reply to deleted_user
    Data organization should be given critical thought when designing a solution. The way data are arranged will affect the complexity of the implementation and performance.

    Views provide a mechanism for rearranging data without replicating them on disk. When different applications rely on the same data, yet each implementation would prefer a different layout, views often provide a sufficient solution.

    -- Jason Secosky, SAS R&D / DATA Step
    Ask a Question
    Discussion stats
    • 4 replies
    • 194 views
    • 0 likes
    • 2 in conversation