rogerzebra
Technical User
Hi All,
I was hoping for someone to help me out on how to use cursors and declared tables using t-sql in SAS. I keep getting this error message when i execute the script.
Here is parts of my script
I appreciate all help and thanking you in advance.
/r
I was hoping for someone to help me out on how to use cursors and declared tables using t-sql in SAS. I keep getting this error message when i execute the script.
Code:
/*----------- declared variables ---------------*/
17 declare @CustomerID CHARACTER(12)
_______
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
Code:
declare @Name2 table
(
Customer_ID CHARACTER(12)
,Name1 CHARACTER(35)
,Name2 CHARACTER(35)
,Name3 CHARACTER(35)
,Name4 CHARACTER(35)
)
insert into @Name2
(
Customer_ID
,Name1
)
select a3.Customer_id, b.Name
from Table a3
inner join @Name b on a3.customer_id = b.customer_id
Group by a3.customer_id,b.Name
/*select * from @Name2*/
/*----------------------End @Name2--------------------------*/
/*----------------------#one--------------------------*/
create table #one
(
seq int identity(1,1) not null
,Customer_ID CHARACTER(12)
,Name CHARACTER(35)
)
declare subcur cursor for
select Customer_ID
from @Name2
Open subcur
fetch next from subcur into @CustomerID
while @@Fetch_Status = 0
begin
Truncate table #one
insert into #one
(
customer_id
,Name
)
select @CustomerID
,ltrim(n1.Name) as Name
from Table a4
inner join @Name n1 on a4.customer_id = n1.customer_id
where a4.customer_id = @CustomerID
group by a4.customer_id
select @count = max(seq) from #one
if @count >=1
begin
update @Name2
set
Name2 = n1.Name
from #one o
inner join @Name2 n2 on o.customer_id = n2.customer_id
where o.seq = 1
end
..etc
/r