Hii,
I have a created an ADSL dataset with multiple studies and I loaded this dataset in to a database to build a data repository.
Now, I need to retrieve this ADSL dataset from Database to my study folder where studyid = 6300.
From Data Management team I got below command and said to execute the following procedure in SAS proc sql:
EXEC bst.usp_ADS_SHOW_DATASET '6300', 'ADSL'.
I didn't understand how to use mentioned command to retrieve the dataset. Can anyone suggest me a solution for this.
FYI:
I have tried below code but it didn't worked to me.
libname p2_ads oledb init_string = "Provider = SQLOLEDB.1;
BULKLOAD = YES;
Integrated Security = SSPI;
Persist Security Info = True;
Initial Catalog = VCDM_ANALYxxTIC;
Data Source = ITSUSRAxxxxx,1000"
Schema = BST;
;
proc sql;
create table adsl33 as
select *
from EXEC p2_ads.usp_ADS_SHOW_DATASET, "6300", "ADDX"
;
quit;
LOG:
150 proc sql;
151 create table adsl33 as
152 select *
153 from EXEC p2_ads.usp_ADS_SHOW_DATASET, "6300", "ADDX"
-
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, ',', ANSIMISS, CROSS, EXCEPT,
FULL, GROUP, HAVING, INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER,
RIGHT, UNION, WHERE.
ERROR 76-322: Syntax error, statement will be ignored.
154 ;
155 quit
Thank You for your time,
Santhosh.
To execute an SQL Server stored procedure you will probably need to do something similar to this:
PROC SQL;
Connect to oledb (datasrc=ITSUSRAWSP02788,1433 user = skumar password =);
Execute(EXEC bst.usp_ADS_SHOW_DATASET '6300', 'ADSL';) by oledb;
Disconnect from oledb;
QUIT;
Please note you have to include the EXEC inside the brackets to tell SQL Server to run a stored procedure. Also note you can't add a SELECT statement in front of the SAS EXECUTE to read data. That has to be done in a separate SQL statement.
Hi @Kumar6
You need an SQL Pass through query to execute a SQL server Stored Process.
Syntax looks like this :
PROC SQL;
Connect to odbc (datasrc=<data source name> user = <user name> password = <pwd>);
Execute(p2_ads.usp_ADS_SHOW_DATASET, "6300", "ADDX") by odbc;
Disconnect from odbc;
QUIT;
You probably need to take a step-by-step approach to make this work.
Step 1: Connectivity to the database.
You wrote that you've loaded data into a database table. Did you use SAS for this? If yes then make sure that you're using the exact same libname/libref now.
If not: Try and see if there is already a SAS library defined for you (i.e. for SAS EG/Studio under the Server). If there is one activate the library (assign) and drill into it. Or: Is there someone else using SAS to connect to this database? If yes then get this already working libname statement from this person.
Step 2: List table metadata
IF you've got a library defined then issue below statement (let's assume the libref is called mylib). Does this work? And in the report created do you see the table name you're after?
proc contents data=mylib._all_ short; run;
Let's discuss step 3 once above is working. It should be simple and if you just need data read into SAS will likely not require a stored procedure.
To execute an SQL Server stored procedure you will probably need to do something similar to this:
PROC SQL;
Connect to oledb (datasrc=ITSUSRAWSP02788,1433 user = skumar password =);
Execute(EXEC bst.usp_ADS_SHOW_DATASET '6300', 'ADSL';) by oledb;
Disconnect from oledb;
QUIT;
Please note you have to include the EXEC inside the brackets to tell SQL Server to run a stored procedure. Also note you can't add a SELECT statement in front of the SAS EXECUTE to read data. That has to be done in a separate SQL statement.
@Kumar6 You need to use SQL passthru for your SELECT statement:
Create table tst.adsl3 as
select *
from connection to oledb
(select * from
bst.usp_ADS_SHOW_DATASET
);
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.