BookmarkSubscribeRSS Feed
Banu
Obsidian | Level 7
Hi Everyone,

I have a requirement to read a text file which contains SQL query into a single column in SAS Dataset. Could you please help.

For Example, I have a emp.txt file and which contains below query.
Select * from emp where sal > 5000 and deptno=30;

Above one is simple query, but I have big queries too. Thank you.
3 REPLIES 3
PaigeMiller
Diamond | Level 26

SAS data sets do not usually contain SQL code, they usually contain data. Are you sure that is the requirement? SAS data sets would be a poor choice for a place to store code. Could it be that the requirement is to read SQL code into a SAS program?

--
Paige Miller
Banu
Obsidian | Level 7
This is part of one of the automation. Users will give me one query, and I will need to break that query into all possible queries using where clause column /conditions to verify which query throwing 0 records.

Ex:
Query1: select * from emp where sal>5000;
Query2: select * from emp where sal>5000 and deptno=30;
Once I make the diff queries based on the input query, will submit queries to find whether all queries populating data or not.

As part of this, first I want to read the query into a single column in SAS Dataset.
Tom
Super User Tom
Super User

@Banu wrote:
This is part of one of the automation. Users will give me one query, and I will need to break that query into all possible queries using where clause column /conditions to verify which query throwing 0 records.

Ex:
Query1: select * from emp where sal>5000;
Query2: select * from emp where sal>5000 and deptno=30;
Once I make the diff queries based on the input query, will submit queries to find whether all queries populating data or not.

As part of this, first I want to read the query into a single column in SAS Dataset.

Reading text from a file is trivial. 

 

Making sense of it as SQL syntax is difficult.

 

One restriction is that character variables can only store 32K bytes.  So your will have a limit on how large a block of code you can put into a single variable.

data want;
  infile 'codefile' truncover ;
  input codeline $32767.;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 885 views
  • 0 likes
  • 3 in conversation