conditionally run proc sql

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

conditionally run proc sql

[ Edited ]

i am somewhat new to sas, so what i want to do is execute some sql only on a certain month.  so i want...

 

proc sql;

update table

set field='Y';

;

 

to run in a larger program only when the month is january.  i am sure it is a fairly easy solution, just having trouble finding the right one.  i am using sas eg 7.1 tyi. 

 

thanks


Accepted Solutions
Solution
‎04-06-2017 02:47 PM
Super User
Posts: 5,495

Re: conditionally run proc sql

First, you will need working PROC SQL code.  I leave that to you as a separate issue.  For a short program like you have illustrated, here is an easy way:

 

data _null_;

if month(today())=1 then call execute(

"proc sql;

update table

set field='Y';

;"

);

run;

View solution in original post


All Replies
Solution
‎04-06-2017 02:47 PM
Super User
Posts: 5,495

Re: conditionally run proc sql

First, you will need working PROC SQL code.  I leave that to you as a separate issue.  For a short program like you have illustrated, here is an easy way:

 

data _null_;

if month(today())=1 then call execute(

"proc sql;

update table

set field='Y';

;"

);

run;

Super User
Posts: 11,338

Re: conditionally run proc sql

I am not quite sure if you want to conditionally execute Proc Sql or if you only want to process some records within a data set based on the value of a variable in the data set.

Contributor
Posts: 26

Re: conditionally run proc sql

[ Edited ]

yeah, that worked out great but while i was waiting i also wroote a macro to do that same thing...

 

%let mnth=%sysfunc(month(%sysfunc(today())));
%macro monthtest;
%if &mnth^=4 %then %do;
proc sql;
select * from TABLE where ID<=100;
%end;
%else %if &mnth=4 %then %do;
proc sql;
select * from TABLE where 100<=ID<=200;
;
%end;
%mend monthtest;
run;

%monthtest
run;

 

...and to the other questions, what i needed to do was based on whether it was jan or not, if so i needed to mark some delete=y under 2 certain conditions of other columns in the data. 

☑ This topic is solved.

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

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