Help using Base SAS procedures

need help to modify the records in a variable.

Reply
New Contributor
Posts: 4

need help to modify the records in a variable.

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')

 

 

New Contributor
Posts: 4

Need help to modify the records in a variable

 

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')

Super User
Posts: 10,526

Re: Need help to modify the records in a variable

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.

New Contributor
Posts: 4

Re: Need help to modify the records in a variable

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

Super User
Posts: 17,889

Re: Need help to modify the records in a variable

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...

Super User
Posts: 17,889

Re: Need help to modify the records in a variable

This will also never evaluate to true:

 

(where t1.star_first_name=(leo) and t1.star_first_name=(brad))
New Contributor
Posts: 4

Re: Need help to modify the records in a variable

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.

Ask a Question
Discussion stats
  • 6 replies
  • 245 views
  • 0 likes
  • 3 in conversation