×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to use declared tables and cursors using t-sql in SAS?

How to use declared tables and cursors using t-sql in SAS?

How to use declared tables and cursors using t-sql in SAS?

(OP)
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.

CODE

/*----------- declared variables ---------------*/
17         declare @CustomerID CHARACTER(12)
           _______
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
Here is parts of my script

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
I appreciate all help and thanking you in advance.
/r

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close