BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi guys

I want to extract logins from table to userlist variable and substitute it to the where clause. Here is a piece of code:

%let in=work.MetaLogins;
proc sql noprint;
select Login
into :userlist separated by "','"
from ∈
quit;

%let userlist = '&userlist';
data logins;
set xml.Login;
where UserID in (&userlist);
run;

I am tired of that. Help me please to force it work.

Thanks.
1 REPLY 1
Olivier
Pyrite | Level 9
I think your problem is that LOGIN is a character variable, hence lacking quotes in the WHERE statement. When you add the external quotes in the %LET statement, the &userlist is not resolved, because simple quotes (') BLOCKS the macro resolution. Instead of adding them in the "SEPARATED BY" part, try this : combination of LEFT, TRIM (to remove trailing blanks) and QUOTE (adds quotes) functions in the SELECT clause, and only SEPARATED BY commas.
[pre]
%let in=work.MetaLogins;
proc sql noprint;
select QUOTE(LEFT(TRIM(Login)))
into :userlist separated by ","
from ∈
quit;

data logins;
set xml.Login;
where UserID in (&userlist);
run;
[/pre]
Regards.
Olivier

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
  • 1 reply
  • 605 views
  • 0 likes
  • 2 in conversation