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-2024.png

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.

 

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