BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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).

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

1 REPLY 1
Reeza
Super User

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);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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