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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 4570 views
  • 0 likes
  • 3 in conversation