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

Hello guys.
I am working on sas Stored process.
where i need to process multiple values from single prompt.
For example,
prompt name = Brand.
after selecting multiple values (for now assume 4 values)it auto creates variables &Brand_count, &Brand1,&Brand2,&Brand3,&Brand4.
so to use these prompt values I implement these prompts (&Brand1,&Brand2,&Brand3,&Brand4) in code.
The code runs nicely if I give exactly 4 values,
but after passing values more or less than 4 (let's say 3 or 5 values)
then it gives error.
If someone facing the same issue or have solution .please help me.

i am working on SAS enterprise guide 7.1

Thanks...

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

See a simple example for building an in-list in SQL:

%let namecount=3;
%let name1=Alfred;
%let name2=Joyce;
%let name3=Robert;

%macro select_from_prompt;
proc sql;
create table want as
select * from sashelp.class
where name in (
%do i = 1 %to &namecount;
  %if &i > 1 %then ,;
  "&&name&i"
%end;
);
quit;
%mend;
%select_from_prompt

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

It is difficult to guess what was the programmer intention.

As the prgram is stored, I suspect if you have the source.

 

If the program requires 4 values. try enter '*' as dummy value.

Sujeet
Calcite | Level 5

 

Hi , Shmuel,  

I tried dummy values. but only first value from multiple values is accepted while execution.

 

and also tried to use IF ELSE but it does not work.

%if &BRAND_COUNT=2 %then 
                            "&brand2";
             %else %do i=1 %to &BRAND_COUNT;
                         "&&brand&i"
             %end; 
               
    quit;

 

Kurt_Bremser
Super User

See a simple example for building an in-list in SQL:

%let namecount=3;
%let name1=Alfred;
%let name2=Joyce;
%let name3=Robert;

%macro select_from_prompt;
proc sql;
create table want as
select * from sashelp.class
where name in (
%do i = 1 %to &namecount;
  %if &i > 1 %then ,;
  "&&name&i"
%end;
);
quit;
%mend;
%select_from_prompt
Sujeet
Calcite | Level 5

Hi Kurt ,

thank you.

you are right . Looping the values is the only way i can see now. 

your example is very useful.

now i am experimenting with your example .

let's see if it works

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2148 views
  • 3 likes
  • 3 in conversation