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-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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