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

Hi,

 

I'm trying to create a prompt where the user can paste great amount of values. I insert the prompt in the where clause on a query builder with an In a list operator but when I run it the prompt only give me the option to enter one value at a time.

 

I try to put the prompt in a filter a sort task as seen in code below but this task does not recognize the prompt.

 

%LET CIF = s1;
%LET CIF_count = 1;
PROC SQL NOEXEC;
SELECT t2.CIF,
t2.CLIENTE,
t1.NO_CUENTA,
t2.CEDULA,
t2.PASAPORTE,
t2.RNC,
t2.SEGMENTO,
t1.TIPO_CUENTA
FROM WORK.QUERY_FOR_CUP0_0000 t2
INNER JOIN WORK.QUERY_FOR_CUP0_0001 t1 ON (t2.CIF = t1.CIF)
WHERE t1.TIPO_CUENTA IN
(
'SOW',
'IND',
'JAF',
'JOF'
) AND %_eg_WhereParam( t2.CIF, CIF, IN, TYPE=S, IS_EXPLICIT=0 )
ORDER BY t2.CLIENTE;
QUIT;

Any idea?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

There is no need to put in the commas.

SAS is very happy to accept spaces as delimiters.

%let PromptText=13  14;
proc print data=sashelp.class ;
 where age in (&PromptText);
run;

Now if the variable you are comparing to is character then you will need to add quotes if the pasted values do not already include them.  If you make sure to change multiple spaces to one then using TRANWRD() to change spaces to quoted spaces will do it for you.

%let PromptText=Alice   Alfred;
%let PromptText=%sysfunc(compbl(&PromptText));
proc print data=sashelp.class ;
where name in (
"%sysfunc(tranwrd(&prompttext,%str( )," "))"
);
run;

 

View solution in original post

12 REPLIES 12
TomKari
Onyx | Level 15

Exactly what form does the text that your user pastes in take? That will help figure out how to put it into your SQL. Please give an example of exactly what they would paste.

 

Tom

rodrichiez
Quartz | Level 8

Hi Tom,

 

They would pastes identification value of a client, is character type. This one is an example: 0005164890. Sometimes they would need to pastes up to 700 values.

 

Regards.

TomKari
Onyx | Level 15

What I was trying to ask was the exact format. So, for instance, would it be

 

0005164890
0005164917

 

or

 

0005164890,
0005164917

 

or

 

0005164890, 0005164917

 

or

 

0005164890 0005164917

 

rodrichiez
Quartz | Level 8

Hello Tom,

 

It would be the first one:

 

0005164890
0005164917

TomKari
Onyx | Level 15

So here's what I got working. Set up a prompt, as a text field, option Multi-line text. I named mine "PromptText". When I ran it, I pasted in

11
14
16

as the text.

 

I wrote this program:

 

data _null_;
	PromptText = transtrn("&PromptText.", " ", ", ");
	call symput("InClause", strip(PromptText));
run;

proc sql noprint;
	create table Want as
		select * from sashelp.class
			where Age in(&InClause.);
quit;

At some point it seems the carriage returns are converted to spaces. The first program converts spaces to ", ", and loads it back into a macro variable. The second step runs the query.

 

There may be a little more futzing required, but hopefully this will get you on the way.

 

Tom

 

 

Tom
Super User Tom
Super User

There is no need to put in the commas.

SAS is very happy to accept spaces as delimiters.

%let PromptText=13  14;
proc print data=sashelp.class ;
 where age in (&PromptText);
run;

Now if the variable you are comparing to is character then you will need to add quotes if the pasted values do not already include them.  If you make sure to change multiple spaces to one then using TRANWRD() to change spaces to quoted spaces will do it for you.

%let PromptText=Alice   Alfred;
%let PromptText=%sysfunc(compbl(&PromptText));
proc print data=sashelp.class ;
where name in (
"%sysfunc(tranwrd(&prompttext,%str( )," "))"
);
run;

 

rodrichiez
Quartz | Level 8
Thank you TomKari!!
rodrichiez
Quartz | Level 8

Hi Tom,

 

When I try to run the code I get this error:

 

28
29 proc sql;
30 create table work.test as
31 select * from WORK.QUERY_FOR_CUP0_0001_0000 t1
32 where t1.CIF in(&InClause.);
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
NOTE: Line generated by the macro variable "INCLAUSE".
32 s1
__
22
202
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
a missing value, (, -, SELECT.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

 

And I can't paste more than one value at a time.

 

TomKari
Onyx | Level 15

First, let's figure out if your program is picking up the macro variable. Put the line:

 

%put &InClause.;

 

above the "proc sql;" line, and see if the log contains something reasonable.

 

Tom

rodrichiez
Quartz | Level 8

Hello Tom,

 

It is working now, what I forgot was to configure a multiline prompt. But I realized that the form of the value must be:

 

'0000000085',
'0000000086',
'0002746556',

 

So I need to add quotation marks and commas.

FredrikE
Rhodochrosite | Level 12

Is the prompt-query added to the sort task properties?

Check it out by right-click on the sort task, select properties and then queries.

If the prompt is not added, just add it and hopefully it works 🙂

//Fredrik

rodrichiez
Quartz | Level 8

Hello Fred,

 

There is not such option in the properties of filter and sort task.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 12 replies
  • 6197 views
  • 2 likes
  • 4 in conversation