BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jdmarshg
Obsidian | Level 7

Good morning everyone,

I have learned how to call a stored procedure in stored procedure.

I have still yet to be able to using SQL Pass Thru if the correct approach to pass a macro variable into a stored procedure residing in SQL Server.

Will post more code shortly as I continue to research and try different methods.

Regards,

Jonathan Marshall

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

Yes they do mix, but you need to take into count differences in quoting syntax.

If you need single quotes around your job I'd you might get some help from this usage note:

13485 - How to pass a macro variable into the WHERE clause to query an Oracletable with PROC SQL Pas...

Data never sleeps

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

Ok, hear from you soon 🙂

Data never sleeps
jdmarshg
Obsidian | Level 7

I have used this code to call a job within sql server with a hard coded value for the parameter job_name.

I'm looking to take a macro variable and pass it into the sql server stored procedure.

How would I go about doing that?

proc sql;

  connect to SQLSVR as SQLDB

    (datasrc="&datasrc");

  select * from connection to SQLDB

/*( EXECUTE msdb.dbo.sp_start_job @job_id = 'E9B5D67A-0695-49F1-8CE2-388671ECB4B6');*/

( EXECUTE msdb.dbo.sp_start_job @job_name = 'job_name');

  disconnect from SQLDB;

quit;

Regards,

Jonathan

user24feb
Barite | Level 11

I think the explicit pass-through and the macro-variable don't mix. Try something like this:

%Let datasrc=Macro_datasrc; *!;
%Let job_name=Macro_job_name;

Data Command;
  Length Cmd $100.;
  Cmd="Proc SQL;"; Output;
  Cmd=Catt("   connect to SQLSVR as SQLDB (datasrc=","&datasrc.",");"); Output;
  Cmd=Catt("   select * from connection to SQLDB ( EXECUTE msdb.dbo.sp_start_job @job_name = '","&job_name.","');"); Output;
  Cmd="   disconnect from SQLDB;"; Output;
  Cmd="Quit;"; Output;
Run;

Data _NULL_;
  Set Command;
  Call Execute (Cmd);
Run;

LinusH
Tourmaline | Level 20

Yes they do mix, but you need to take into count differences in quoting syntax.

If you need single quotes around your job I'd you might get some help from this usage note:

13485 - How to pass a macro variable into the WHERE clause to query an Oracletable with PROC SQL Pas...

Data never sleeps
jdmarshg
Obsidian | Level 7

OOOOH Yes....

It tried the approach Linus placed forth..

In so many searches why have I not found this link... 13485 - How to pass a macro variable into the WHERE clause to query an Oracletable with PROC SQL Pas...

I just got it to work.... I'm coming from the SSIS world so of course SSIS to SQL Server is merely built in but this case just opens soo many doors with integration with SQL Server.

I'm now going to try user24feb approach

This made my day ....

many thanks

%let dataset_name = Jonathan;

proc sql;

connect to SQLSVR as SQLDB

(datasrc="DEV04Kerberos");

select * from connection to SQLDB

(EXECUTE Jonathan.dbo.InsertNewSchema @SchemaName = %unquote(%str(%'&dataset_name%')));

disconnect from SQLDB;

quit;

Regards,

Jonathan

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1903 views
  • 3 likes
  • 3 in conversation