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

I have several datasets (.sas7bdat files in libname 'dataset') that I'm trying to read into my program.  I only want to keep variables that contain 'ID' in the name. I have code that does what I want it to do, but I want to put it in a macro.

 

When I run the code in the macro I created, I have an issue at the PROC SQL/%PUT part of my code and I get warning that says, "No rows selected.......no KEEP variables found, statement ignored."  Thus, it reads in the datasets in but doesn't keep the variables I want.  

 

Any suggestions?  Thank you. 

%macro datain(old,new,final);
   data &new;
   set dataset.&old;
   run;

proc sql noprint;
select trim(compress(name))
into :keep_vars separated by ' '
from dictionary.columns
where libname = upcase('work')
and memname = upcase('&new.')
and upcase(name) like '%ID%';
quit;

%put &keep_vars.;

data &final;
set &new;
keep &keep_vars.;
run;
%mend datain;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Single quotes prevent resolution of macro variables:  ('&new.')

 

Use double quotes instead:  ("&new.")

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@glcoolj12 wrote:

I have several datasets (.sas7bdat files in libname 'dataset') that I'm trying to read into my program.  I only want to keep variables that contain 'ID' in the name. I have code that does what I want it to do, but I want to put it in a macro.

 

When I run the code in the macro I created, I have an issue at the PROC SQL/%PUT part of my code and I get warning that says, "No rows selected.......no KEEP variables found, statement ignored."  Thus, it reads in the datasets in but doesn't keep the variables I want.  

 

Any suggestions?  Thank you. 


Really, we don't know what variables you have. This could be a completely correct result. We don't know. And we can't debug this ... unless ... you show us that you do indeed have variables with ID in the name, perhaps by showing us a PROC CONTENTS or the appropriate parts of sashelp.vcolumn.

--
Paige Miller
Astounding
PROC Star

Single quotes prevent resolution of macro variables:  ('&new.')

 

Use double quotes instead:  ("&new.")

glcoolj12
Obsidian | Level 7
This fixed the issue - thank you so much!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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