Creation date: 01/04/2000
Authored by: Karl Ho
Question:
Manipulating long list of variables in DATA step
Answer:
When you deal with a list of variables in SAS, you can use the hyphen (-) to manipulate
the variables. The following SAS program demonstrates the use of hyphen in a DATA
step*:
data test1;
input var1 cvar2 $ var3 var4 var5 $;
drop var1-var4;
cards;
1 2a 3 5555 notsug
5 6a 7 8888 usergrp
;
proc print;
run;
This program creates five variables from VAR1 to VAR5 and supposedly drops VAR1 to VAR4. However, since in between there is a string variable, CVAR2, the DROP statement only drops VAR1, VAR3 and VAR4, as represented by the list VAR1-VAR4, conditionally. The output is:
The SAS System 5 11:17 Tuesday, January 4, 2000
OBS CVAR2 CVAR5
1 2a notsug 2 6a usergrp
To drop all variables from VAR1 thru VAR4, including CVAR2, the list VAR1--VAR4, with two hyphens, will do. The output is as follows:
The SAS System 6 11:17 Tuesday, January 4, 2000
OBS CVAR5
1 notsug 2 usergrp
* This FAQ is adapted from the Tips and Techniques published in the January 2000 issue of NoTSUG News, authored by the Editor Mark MacMullen. The NoTSUG News is a publication of the North Texas SAS User's Group.
Last updated: 01/16/2006 by Karl Ho