BookmarkSubscribeRSS Feed
mrscher22
Calcite | Level 5
I have a cursor that I would like to execute via proc sql in base SAS. Is this possible?

here is my code:


declare
v_cust_id int;
v_sales_rep_id int;

cursor orphan_cursor is
select cust_id
from DTF_SALES_ITS_recur_5
order by cust_id desc;

cursor reps_cursor is
select sales_rep_id
from DTF_SALES_ITS_recur_reps2
order by rand_number;

begin
open reps_cursor;
for orph_val in orphan_cursor
loop
fetch reps_cursor into v_sales_rep_id;
if reps_cursor%notfound then
close reps_cursor;
open reps_cursor;
fetch reps_cursor into v_sales_rep_id;
end if;
v_cust_id := orph_val.cust_id;
INSERT into univ_assign_orphans VALUES (v_cust_id, v_sales_rep_id);
end loop;
close reps_cursor;
end;
2 REPLIES 2
deleted_user
Not applicable
1) Wouldn't it make more sense to either run this from SQL Plus? or as a stored procedure?

2) You may be able to use the pass-through facility and execute statement.

3) Does your code have some typo's, because it doesn't look like it would work as intended to me.

4) It seems to me that if you want to use SAS and determine if there are orphaned customer id's and sales_rep id's, you could use proc sql directly with some set relations:
[pre]
proc sql;
select something from somewhere
except corr
select something from somewhereelse;
quit;
[/pre]
deleted_user
Not applicable
Thanks for the reply, Chuck.

I seems like your suggestion of using a stored proc is the right answer to my problem. The semi-colon in the code is the culprit even though it is in the passthrough statement, SAS parses the statement before passing it over to the dbms.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1547 views
  • 0 likes
  • 2 in conversation