BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10
use D_LM								
go								
#NAME?								
								
declare @medate as datetime								
								
select @medate = '09/30/2020'								
								
CREATE TABLE #TEMP								
(ALS_NUM varchar(20),								
LMID	bigint,							
MOD	int,							
LEV	int,							
RELATED	bigint,							
pri_ssn	varchar(9),							
LOANLINE varchar(4))								
								
DECLARE @i 		tinyint						
SELECT @i = 2								
#NAME?								
INSERT #TEMP								
SELECT ORG_ALS_NUM, LMDB_ID, RECOMMEND, 1, NULL, pri_ssn,LOANLINE								
FROM d_lm.ALLBooked 								
WHERE MONTH(DATE_BOOKED) = MONTH(@MEDate) AND YEAR(DATE_BOOKED) = YEAR(@MEDate)								
								
								
								
--Now search these and see if any of these are new acct nubers for a prior 'booked' loan								
--loop 5 times to find any more iterations of the same loan								
								
WHILE @i < 10								
BEGIN								
	INSERT #TEMP							
	SELECT v.ORG_ALS_NUM, v.LMDB_ID, v.RECOMMEND, @i, t.LMID , v.pri_ssn, v.LOANLINE							
	FROM d_lm_ALLBooked v 							
	JOIN #TEMP t 							
	ON (t.ALS_NUM = v.NEW_ALS_NUM 							
	or t.als_num = v.org_als_num)							
	AND v.LMDB_ID NOT IN (SELECT LMID FROM #TEMP)							
	SELECT @i = @i + 1							
END								

You cannot run this code however her is my question.  The code came to me in T-SQL format.  I am trying to run each section and produce a dataset so I can get a visual on how to connect the datasets.  Can this be dumped into a third party app like toad or SSRS.  What have some of you utilized in cases like this?

2 REPLIES 2
SASKiwi
PROC Star

Why do you need to decode? You can continue to run this code as is from SAS using SQL Passthru and the EXECUTE statement. If the results need to come back to SAS you can read the #temp table in a following SQL query.

Sajid01
Meteorite | Level 14

Hello @Q1983 '

You should follow what  @SASKiwi has advised.

However if you want to run it in an external application use SQL Server Management Studio. This is a free GUI tool for executing T-SQL code on Microsoft SQL Server.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 508 views
  • 1 like
  • 3 in conversation