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...
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
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.
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;
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
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
I guess you need to do everything in a loop:
%do i = 1 %to &brandcount;
and use indirect addressing like
&&brand&i
But that's all guesswork without seeing the code.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.