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;
Single quotes prevent resolution of macro variables: ('&new.')
Use double quotes instead: ("&new.")
@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.
Single quotes prevent resolution of macro variables: ('&new.')
Use double quotes instead: ("&new.")
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.