BookmarkSubscribeRSS Feed
npatel2302
Calcite | Level 5

I have a dataset variable with a sql query in it, and i want to put the words in the parantheses into quotations to read that query from SAS.Not  sure how can i do that. Can any one please help?

 

Example-

select t1.star, t2.movies,t1.origin

from (select movies, origin from movie_list where origin=(USA)) t2

left outer join star_names t1

on t1.origin=t2.origin

(where t1.star_first_name=(leo) and t1.star_first_name=(brad))

;

 

I want to put USA, leo and brad into single quotations like -('USA') ('leo') ('brad')

 

 

6 REPLIES 6
npatel2302
Calcite | Level 5

 

I have a dataset variable with a sql query in it, and i want to put the words in the parantheses into quotations to read that query from SAS.Not  sure how can i do that. Can any one please help?

 

Example-

select t1.star, t2.movies,t1.origin

from (select movies, origin from movie_list where origin=(USA)) t2

left outer join star_names t1

on t1.origin=t2.origin

(where t1.star_first_name=(leo) and t1.star_first_name=(brad))

;

 

I want to put USA, leo and brad into single quotations like -('USA') ('leo') ('brad')

ballardw
Super User

The easiest way to get imbedded quotes is to use a different quote.

You do not describe how you created the data set in the first place, which would probably be the best place to do this.

Assuming you had something like

x='select t1.star, t2.movies,t1.origin
from (select movies, origin from movie_list where origin=(USA)) t2
left outer join star_names t1
on t1.origin=t2.origin
(where t1.star_first_name=(leo) and t1.star_first_name=(brad))
;
'  ;

Then something like this

 

x='select t1.star, t2.movies,t1.origin
from (select movies, origin from movie_list where origin=("USA")) t2
left outer join star_names t1
on t1.origin=t2.origin
(where t1.star_first_name=("leo") and t1.star_first_name=("brad"))
;
'  ;

Note the use of the " between the '   ' that define the long string value.

 

 

We may need more details on how you are building you dataset if you are not using simple assignments.

npatel2302
Calcite | Level 5

The data is coming from one of the sql server table. Variable name is query_text which basically has the list of query associated with the claims processing. The output that you mentioned will not work as i will have run the whole query to SQL sever again using will be using macro for that, and double quotes might not work.

 

Hope that helps

Reeza
Super User

What do you want as a final result?

 

I'm not seeing why you can't just type single quotes into your query at the moment...

Reeza
Super User

This will also never evaluate to true:

 

(where t1.star_first_name=(leo) and t1.star_first_name=(brad))
npatel2302
Calcite | Level 5

Thanks for help Reeeza.

So in brief, i have a dataset with obs_number, query_text and application id, and that data is coming from one SQL server table.

Example of Query_text -

Select * from Table1 t1

left outer join Table2 t2

( t1.CASE_STATUS_TYPE_CD = (NEW) OR t1.CASE_STATUS_TYPE_CD = (OPEN) ) AND ( t3.SEARCH_VALUE_NAME = (HighVal_Ind) AND t3.SEARCH_VALUE_NUM <= 3 ) AND ( t4.SEARCH_VALUE_NAME = (Curr_Strategy) AND t4.SEARCH_VALUE_STRG = (095) ) GROUP BY t1.CASE_REFERENCE_NUM,t2.LAST_SCRFP_FRD_CARD,t1.SERVICE_XID ORDER BY t2.LAST_SCRFP_FRD_CARD DESC

 

What i need to do in sas is to put quotations in to the character records as below

Select * from Table1 t1

left outer join Table2 t2

( t1.CASE_STATUS_TYPE_CD = (NEW) OR t1.CASE_STATUS_TYPE_CD = ('OPEN') ) AND ( t3.SEARCH_VALUE_NAME = ('HighVal_Ind') AND t3.SEARCH_VALUE_NUM <= 3 ) AND ( t4.SEARCH_VALUE_NAME = ('Curr_Strategy') AND t4.SEARCH_VALUE_STRG = ('095') ) GROUP BY t1.CASE_REFERENCE_NUM,t2.LAST_SCRFP_FRD_CARD,t1.SERVICE_XID ORDER BY t2.LAST_SCRFP_FRD_CARD DESC

 

Hope that clarifies my question.

 

Thanks a lot.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1640 views
  • 0 likes
  • 3 in conversation