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.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
  • 5 replies
  • 2334 views
  • 3 likes
  • 3 in conversation