BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
me55
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
Astounding
PROC Star

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;

ballardw
Super User

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.

me55
Quartz | Level 8

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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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