DATA Step, Macro, Functions and more

Macro in drop and keep statement

Reply
Contributor
Posts: 56

Macro in drop and keep statement

I defined a macro for the number of variables say,
and I wanna drop the variabes in my data step,

%let num = 5;
data xx;
set yy;
drop var1 - var#
run;

This doesn't work for such consecutive selection.Any idea to make it work? Thanks and Regards.

Message was edited by: Fred_Gavin
Super Contributor
Super Contributor
Posts: 3,174

Re: Macro in drop and keep statement

Posted in reply to Fred_Gavin
Please elaborate on what doesn't work - possibly show how you want your SAS variables to appear at input and then at output (DATA step completion), including in your post one or more DATA steps as you mention "consecutive selection".

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 56

Re: Macro in drop and keep statement

The name of the variable in the data, say, is var1, var2, var3, var4, var5. and others.. I want to drop var1 to var 5.

then when I use macro;

%let num = 5;
data xx;
set yy;
drop var1-var#
run;

it results in the error for the statement "var1-var&num".
Super Contributor
Posts: 345

Re: Macro in drop and keep statement

Posted in reply to Fred_Gavin
The error must be outside the code you have posted.
[pre]
data work.start;
input a $ val1 val2 val3 val4 val5;
datalines;
a1 1 2 3 4 5
a2 2 3 4 5 6
a3 3 4 5 6 7
b1 5 4 3 2 1
b2 4 3 2 1 0
;
run;

%let num = 5;

data work.short;
set work.start;
drop val1-val#
run;

%symdel num;
[/pre]
Works as intended.
Super Contributor
Super Contributor
Posts: 3,174

Re: Macro in drop and keep statement

Posted in reply to Fred_Gavin
You will need to share your SAS log information listing the exact error message and the failing SAS code, after reviewing the output yourself. If you using macro code, you will want to specify the following SAS statement to generate the most diagnostics info possible:

OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT MLOGIC;


Hopefully you will see the problem after generating more information with your code execution.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 1073 views
  • 0 likes
  • 3 in conversation