1. Last month ---
Method 1 as below,
%let
mon=%substr(%SYSFUNC(PUTN(%sysfunc(intnx(month,%SYSFUNC(TODAY()),-1)) ,B8601DA.)),1,6);
%put &mon.;
-Method 2 as below,
data a;
MONTH=substr(put(intnx("month",today(),-1),yymmddn8.),1,6);
call symput('MONTH',compress(MONTH));
run;
%put &MONTH.;
/*************************************************************************************/
Last Friday
1.*%let day=20221021; /**** method 1: last working day of last week */
2./*****Method2 show as below*********/
/*******last working day of last week, eg: Friday Normally**/
data a;
day=PUT(INTNX('WEEK', TODAY(),-1,'end')-1,B8601DA.);
call symput('day',compress(day));
run;
%put &day.;
%window WIN_PARAM
#2 @3 'day: last working day of last week after CDW dataset done. Normally is Friday'
#3 @3 'day:'
#3 @15 day 8 attr=underline
;
%display WIN_PARAM;
/*****************************************************************************************************************************************************/
Today-2 工作日
%let date=20211209; /D-2:reporting day/
%let mon=%substr(&date.,1,6);
%let k=7; /past working days in the current reporting month/
%let l=23; /total working days of the reporting month/
*%let lstmon=202111;
/***Method2 shows as below***************D-2**************************/
data a;
date=PUT(INTNX('WEEKDAY', TODAY(),-2,'BEGINNING'),yymmddn8.);/*B8601DA. equal to yymmddn8*/
lstmon=PUT(INTNX('month', TODAY(),0,'BEGINNING')-1,yymmn6.);
yr=substr(date,1,4);
call symput('date',compress(date));
call symput('lstmon',compress(lstmon));
call symput('yr',compress(yr));
run;
data a;
date=PUT(INTNX('WEEKDAY', TODAY(),-2,'BEGINNING'),B8601DA.);
lstmon=substr(compress(PUT(INTNX('month', TODAY(),0,'BEGINNING')-1,B8601DA.)),1,6);
yr=substr(compress(PUT(INTNX('month', TODAY(),0,'BEGINNING')-1,B8601DA.)),1,4);
call symput('date',compress(date));
call symput('lstmon',compress(lstmon));
call symput('yr',compress(yr));
run;
%let mon=%substr(&date.,1,6);
%put &yr.;
/************************ call symput *****************************************/
上个月第一天,上个月最后一天,上个月月份
data _null_;
date_s=put(intnx('month',today(),-1),yymmddn8.);
date_e=put(intnx('month',today(),0)-1,yymmddn8.);
mon=put(intnx('month',today(),0)-1,yymmn6.);
call symput('date_s',date_s);
call symput('date_e',date_e);
call symput(mon', mon);
run;
%put &date_s.;
%put &date_e.;
%put &mon.;
/*************************************************************************************/
%let day=20200430; /*last workingday*/
%let year=%substr(&day.,1,4);
%let month=%substr(&day.,1,6);
%PUT &day.;
%PUT &year.;
%PUT &month.;
DATA A;
month=%substr(&day.,5,2);
IF month<10 THEN MON=%substr(&day.,6,1); ELSE MON=%substr(&day.,5,2);
CALL SYMPUT ('MON',MON);
RUN;
%PUT &MON.;
n_age = intck("year", d_birth, mdy(%substr(&day.,5,2),01,%substr(&day.,1,4)));
/********B8601DA. equal to yymmddn8;*****D-2 工作日(月份)****上周五************************************/
data a;
date=PUT(INTNX('WEEKDAY', TODAY(),-2,'BEGINNING'),yymmddn8.); /*date=D-2*/
day=PUT(INTNX('WEEK', TODAY(),-1,'end')-1,yymmddn8.);/*last Friday of last week*/
mon=PUT(INTNX('WEEKDAY', TODAY(),-2,'BEGINNING'),yymmn6.);
yr=substr(date,1,4);
call symput('date',compress(date));
call symput('day',compress(day));
call symput('mon',compress(mon));
call symput('yr',compress(yr));
run;