BookmarkSubscribeRSS Feed
Fred_Gavin
Calcite | Level 5
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
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Fred_Gavin
Calcite | Level 5
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".
andreas_lds
Jade | Level 19
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 3172 views
  • 0 likes
  • 3 in conversation