DATA Step, Macro, Functions and more

Keep= Option With Range List of Variables ERROR

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 123
Accepted Solution

Keep= Option With Range List of Variables ERROR

[ Edited ]

Here is some sample data:

data have;
  infile datalines;
  input Account Group M15201610 M15201611 M15201612 M30201601 M30201602;
  datalines;
1 1 0 2 2 2 .
0 0 1 2 2 2 .
3 3 0 3 1 2 1
;
run;

Here is what I'm trying to do:

%let criteria=(keep=M15201610-M30201602);

data want;
  set have &criteria.;
run;

Now, I am getting the error:

ERROR: Not all variables in the list M15201610-M30201602 were found.

 

When I put the range of variables as (keep= M15201610-M15201612), it works perfectly fine. The reason I'm doing this keep list in the macro variable is because my real data has many of these M variables and I don't want to have to list them out one by one. They represent dates at the middle of the month and end of month for each year and month. So M15201610 would be October 15, 2016. Is there any way I can get around this error? (don't ask why the dates are labeled this way, I didn't come up with the naming convention).


Accepted Solutions
Solution
‎11-14-2016 04:10 PM
Super User
Posts: 19,817

Re: Keep= Option With Range List of Variables ERROR

Posted in reply to JediApprentice

It's expecting a sequential sequence, ie date1, date2, date3 is specified as date1-date3.

 

If it's not sequential, but the columns are side by side you can try a double dash.

 

%let criteria=(keep=M15201610--M30201602);

View solution in original post


All Replies
Solution
‎11-14-2016 04:10 PM
Super User
Posts: 19,817

Re: Keep= Option With Range List of Variables ERROR

Posted in reply to JediApprentice

It's expecting a sequential sequence, ie date1, date2, date3 is specified as date1-date3.

 

If it's not sequential, but the columns are side by side you can try a double dash.

 

%let criteria=(keep=M15201610--M30201602);
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 210 views
  • 0 likes
  • 2 in conversation