Condition to run a proc sql

Accepted Solution Solved
Reply
Super Contributor
Posts: 371
Accepted Solution

Condition to run a proc sql

Good morning,

Could you please help me with the following problem on condition to run a proc?

I want new_file will be added to original_file only when certain condition meet.

In word, it should look like that:

...

IF criteria_in_newfile=1 then do;

     proc sql;

     create table original_file as select * from original_file as a left join newfile as b

          on a.id=b.id;quit;

end;

However, I don't know how to put into code so SAS can understand.

Thank you for your help.

HHC


Accepted Solutions
Solution
‎06-15-2013 01:13 PM
Respected Advisor
Posts: 4,649

Re: Condition to run a proc sql

So, newFile has only one observation and includes variables criteria and id? You could use something like

proc sql;

select

     case when criteria

          then "create table original_file as select * from original_file as a left join newFile as b on a.id=b.id"

          else "" end

into :nextQuery

from newFile;

&nextQuery.;

quit;

PG

PG

View solution in original post


All Replies
Super User
Posts: 5,256

Re: Condition to run a proc sql

You need to embed your program into a macro,  and there you can make use of % if logic.

Data never sleeps
Super Contributor
Posts: 371

Re: Condition to run a proc sql

Thank you,

Can you be more specific?

HHC

Respected Advisor
Posts: 4,649

Re: Condition to run a proc sql

Or you might generate the join query conditionally in a macro variable with SELECT INTO. What kind of condition on newfile are we talking about? - PG

PG
Super Contributor
Posts: 371

Re: Condition to run a proc sql

Hi,

On new_file, the criteria has 2 value, 0 and 1.

If criteria =1, I need the sql run.

Thank you,

HCC

Solution
‎06-15-2013 01:13 PM
Respected Advisor
Posts: 4,649

Re: Condition to run a proc sql

So, newFile has only one observation and includes variables criteria and id? You could use something like

proc sql;

select

     case when criteria

          then "create table original_file as select * from original_file as a left join newFile as b on a.id=b.id"

          else "" end

into :nextQuery

from newFile;

&nextQuery.;

quit;

PG

PG
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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