Write and run SAS programs in your web browser

Insert Query and Run

Reply
Occasional Contributor
Posts: 13

Insert Query and Run

hi.. am new to SAS, I need to insert a query(eg - select count(distict inc_no) from incident_table) into the table using Dataset.
Second thing is i need to fetch that column and run a proc sql, i mean i need an ouput(count - 60) for the query which has been inserted in the incident_table.
How can i acheive this, pls anyone help me. Thanks in advance.

Super User
Posts: 5,382

Re: Insert Query and Run

Not sure about the purpose of this, perhaps you could clarify the underlying requirement?

But technically, just store the query in a char column in a table.

Then you can use call execute in a data step that reads that table.

Data never sleeps
Occasional Contributor
Posts: 13

Re: Insert Query and Run

Sorry for delay in respond, I have inserted a data in the table, fyr, 

make

select count(make) from auto

I need an output of the above query, how can i get it. thanks.

Super User
Posts: 19,047

Re: Insert Query and Run

Look into CALL EXECUTE or DOSUBL

Occasional Contributor
Posts: 13

Re: Insert Query and Run

Reeza.. Call execute is not working for me. am new to SAS.. can yu pls share some example pgm..? pls check my code below..
proc sql;
select make from auto
where
make like 'selec%';
call execute (make);
run;

Thanks in advance..

Occasional Contributor
Posts: 13

Re: Insert Query and Run

Anyone pls help on my below query... 

Call execute is not working for me. am new to SAS.. can yu pls share some example pgm..? pls check my code below..
proc sql;
select make from auto
where
make like 'selec%';
call execute ("PROC SQL;");
run;

Thanks in advance..

 

Super User
Posts: 19,047

Re: Insert Query and Run

You don't need anything actually. Your question was confusing. 

Submit the following program

 

 

Proc SQL;

select make

from auto

where make like 'selec%';

quit;

 

See here for basic SAS tutorials as well as links to the free ecourse. 

Occasional Contributor
Posts: 13

Re: Insert Query and Run

Thanks for your respond. for your query am getting a result like,

make
select count(make) from auto group by mpg
there is a query in the variable as shown above, I have got an ouput from your query, what i want is, i need an output for the above query(select count(make) from auto group by mpg) from the variable. 

Super User
Posts: 11,107

Re: Insert Query and Run

It really helps to show some example data. If you have a data set then instructions here https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to create SAS datastep code that can be posted here as text so that we can recreate the intput data.

 

Then show what the desired result for that data.

You are starting in the middle and the desired output is not clear.

Super User
Posts: 19,047

Re: Insert Query and Run

I'm sorry, but it's incredibly unclear on what you're trying to achieve. I can't tell if its a very basic question where you want to run a query and get results or if its something more complex where you're trying to store code in a data set and then execute said code.

 

Please post in more details what you're trying to do, and try and include examples/samples as much as possible.

Ask a Question
Discussion stats
  • 10 replies
  • 446 views
  • 0 likes
  • 4 in conversation