BookmarkSubscribeRSS Feed
ankitpal064
Calcite | Level 5

Hi Team,

 

 i need to pull some data from DATABASE for some about 50000 participants.ppts unique number is present in file which is in char format in database.

code :

 

data abc;

infile abcsajk;

input @001  unique $9.

line = " ' " !! unique !! " ' "

run;

%let ppts; creating macro vraiable 

proc sql;

select unique : line

into ppts

from abc;

quit;

run;

 

proc sql;

database connection;

create table select * from connectio to database(

select * from db.table where unique_id in (&ppts)

 

Problem here is when ppts get resolved statement length get increased then it's length and query do not run.

 

So as per me solution could be if i can use sas dataset in subquery like below

proc sql;

database connection;

create table select * from connectio to database(

select * from db.table where unique_id in (select line from WORK.abc)

but its not working ,

 

Can anyone help or tell me its possible or not.whether we can uses sas dataset in subquery

 

 

3 REPLIES 3
SASKiwi
PROC Star

Yes it is possible but you need to upload the SAS table into the database first so both tables are in the same environment. The best way is to create a temporary database table containing the SAS data you wish to use for subsetting.

 

What database are you using and does your user name have the database permissions to create a temporary table? You may need to confirm this with a DBA.

ballardw
Super User

If I understand your issue is that the variable Line is too long. So specify the maximum length before use:

data abc;
infile abcsajk;
input @001  unique $9. ;
length line $ 15;
line = " ' " !! unique !! " ' ";

run;

Also if you do not want spaces in line then consider

 

line = quote(unique);

Did actually want to insert spaces before and after each ' in the value of line? If not either quote as above or use length 11 and "'" instead of the " ' ". The later may be easier to read but is adding characters to the variable.

SASKiwi
PROC Star

Also I agree that building a WHERE expression in your case is not going to work with 50,000 unique IDs as the size limit for a macro variable is 64K. Uploading a SAS table is the preferrable option.

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
  • 772 views
  • 1 like
  • 3 in conversation