Desktop productivity for business analysts and programmers

How to create a prompt to enter a list of values

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

How to create a prompt to enter a list of values

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.


Accepted Solutions
Solution
‎07-11-2018 03:27 PM
Super User
Super User
Posts: 8,279

Re: How to create a prompt to enter a list of values

[ Edited ]

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


All Replies
PROC Star
Posts: 1,334

Re: How to create a prompt to enter a list of values

Posted in reply to rodrichiez

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

Contributor
Posts: 28

Re: How to create a prompt to enter a list of values

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.

PROC Star
Posts: 1,334

Re: How to create a prompt to enter a list of values

Posted in reply to rodrichiez

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

 

Contributor
Posts: 28

Re: How to create a prompt to enter a list of values

Hello Tom,

 

It would be the first one:

 

0005164890
0005164917

PROC Star
Posts: 1,334

Re: How to create a prompt to enter a list of values

Posted in reply to rodrichiez

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

 

 

Solution
‎07-11-2018 03:27 PM
Super User
Super User
Posts: 8,279

Re: How to create a prompt to enter a list of values

[ Edited ]

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;

 

Contributor
Posts: 28

Re: How to create a prompt to enter a list of values

Thank you TomKari!!
Contributor
Posts: 28

Re: How to create a prompt to enter a list of values

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.

 

PROC Star
Posts: 1,334

Re: How to create a prompt to enter a list of values

Posted in reply to rodrichiez

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

Contributor
Posts: 28

Re: How to create a prompt to enter a list of values

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.

PROC Star
Posts: 399

Re: How to create a prompt to enter a list of values

Posted in reply to rodrichiez

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 Smiley Happy

//Fredrik

Contributor
Posts: 28

Re: How to create a prompt to enter a list of values

Hello Fred,

 

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 224 views
  • 2 likes
  • 4 in conversation