When kick off jobs for others, it requires to use first day and last day of last month as the parameter. If run sas script file in cron job and pick the time using linux command:
fst_day_this_mon=$(date -d "$date" +01%b%Y)
lst_day_last_mon=$(date -d "-1 day $fst_day_this_mon" +%d%b%Y)
echo fst_day_this_mon=$fst_day_this_mon lst_day_last_mon=$lst_day_last_mon
In SAS we can use intnx function:
## in sas we can use function intnx with optional argument 'B' 'E'
## data _null_;
## x=today();
## stdt=intnx('month',x,-1,'B');
## eddt=intnx('month',x,-1,'E');
## call symput('stdt', put(stdt,date9.));
## call symput('eddt', put(eddt,date9.));
## run;
##
## %put stdt=&stdt eddt=&eddt;
Another similar code to pick the first day is:
d1=$(date -d "-1 month -$(($(date +%d)-1)) days" +"%d%b%Y")
d2=$(date -d "+13 day $d1" +"%d%b%Y")
d3=$(date -d "$d1+14days" +"%d%b%Y")
d4=$(date -d "$d1+27days" +"%d%b%Y")
echo "$d1" "$d2" "$d3" "$d4"
No comments:
Post a Comment