Hi, can any one help me how to overcome the error coming when i am running the below code?? I have used %sysfunc also for firstweek_count variable. But no use.. To get satisfy the condition - %else %If &CurrentQTR. GT 1 %Then %Do; Please add %Let CurrentQTR = 2 ; before executing... Because, if the above condition is True, at that time it is giving errros... Options symbolgen mprint mlogic; %Global Today Today_mmddyyn8 mmdd Currentweek Currentmonth CurrentQTR Currentyear Currentqtryear firstweek_count firstCalDayOfQTR_Date9 FirstCalDayofLastYear LastCalDayofLastQTR weekly_dsvars; Data dates; Today = Today(); Today_mmddyyn8 = Put(Today, mmddyyn8.); /* Today_mmddyy10 = Put(Today, mmddyy10.); */ Current_mmdd = Substr(Put(Today, mmddyyn8.),1,4); Currentweek=Strip(week(Today)); Currentmonth=Month(Today); CurrentQTR = QTR(Today); Currentyear = Year(Today); Currentqtryear = Put(Today, YYMMN.); Call symput("Today", Today); Call symput("Today_mmddyyn8", Today_mmddyyn8); Call symput("mmdd", Current_mmdd); Call symput("Currentweek", Currentweek); Call symput("Currentmonth", Currentmonth); Call symput("CurrentQTR", CurrentQTR); Call symput("Currentyear", Currentyear); Call symput("Currentqtryear", Currentqtryear); Run; %Put &Today. &Today_mmddyyn8. &mmdd. &Currentweek. &Currentmonth. &CurrentQTR. &Currentyear. &Currentqtryear.; %Macro Create_weekly_varlist; %Let i=1; Data qtr_wkly_varlist; %If &CurrentQTR. = 1 %Then %Do; %Let weekly_dsvars = qtr1_wkly_varlist; %Do %while ( &i. LE &Currentweek.); If &i. ne &Currentweek. Then Do; var3 = "week&i._itemfile"; var4 = "week&i._vsi"; Output; end; else Do; new_var1 = "week&i._itemfile"; new_var2 = "week&i._vsi"; weekly_count1 = Left(Trimn(%eval(&i.-1))); weekly_count2 = Left(Trimn(&i.)); Output; end; %Let i = %eval(&i.+1); %end; %end; %else %If &CurrentQTR. GT 1 %Then %Do; %If &Currentmonth. in (4,7,10) %Then %Do; firstCalDayOfMonth = intnx('month',&Today.,0); firstCalDayOfQTR_Date9 = Put(firstCalDayOfMonth,Date9.); LastCalDayofLastQTR = Put(intnx('month',&Today.,-1,'end'),mmddyy10.); FirstCalDayofLastYear = Put(intnx('month',&Today.,-13),mmddyy10.); firstweek_count = Week(firstCalDayOfMonth); Call symputx("firstweek_count", firstweek_count); Call symputx("firstCalDayOfQTR_Date9", firstCalDayOfQTR_Date9); Call symputx("LastCalDayofLastQTR", LastCalDayofLastQTR); Call symputx("FirstCalDayofLastYear", FirstCalDayofLastYear); %end; %If &Currentmonth. in (5,8,11) %Then %Do; firstCalDayOfPrevMonth = intnx('month',&Today.,-1); firstCalDayOfQTR_Date9 = Put(firstCalDayOfPrevMonth, Date9.); LastCalDayofLastQTR = Put(intnx('month',&Today.,-2,'end'),mmddyy10.); FirstCalDayofLastYear = Put(intnx('month',&Today.,-14),mmddyy10.); firstweek_count = Week(firstCalDayOfPrevMonth); Call symputx("firstweek_count",firstweek_count); Call symputx("firstCalDayOfQTR_Date9",firstCalDayOfQTR_Date9); Call symputx("LastCalDayofLastQTR", LastCalDayofLastQTR); Call symputx("FirstCalDayofLastYear", FirstCalDayofLastYear); %end; %If &Currentmonth. in (6,9,12) %Then %Do; firstCalDayOfPrev2Month = intnx('month',&Today.,-2); firstCalDayOfQTR_Date9 = Put(firstCalDayOfPrev2Month, Date9.); LastCalDayofLastQTR = Put(intnx('month',&Today.,-3,'end'),mmddyy10.); FirstCalDayofLastYear = Put(intnx('month',&Today.,-15),mmddyy10.); firstweek_count = Week(firstCalDayOfPrev2Month); Call symputx("firstweek_count",firstweek_count); Call symputx("firstCalDayOfQTR_Date9",firstCalDayOfQTR_Date9); Call symputx("LastCalDayofLastQTR", LastCalDayofLastQTR); Call symputx("FirstCalDayofLastYear", FirstCalDayofLastYear); %end; %Put &firstweek_count. &LastCalDayofLastQTR. &FirstCalDayofLastYear. &firstCalDayOfQTR_Date9.; %Do %while ( &i. LE &Currentweek.); %If &i. GE &firstweek_count. %then %Do; %Let nextweek_count = %eval(&i.- &firstweek_count. + 1); %If &i. ne &Currentweek. %Then %Do; var3 = "week&nextweek_count._itemfile"; var4 = "week&nextweek_count._vsi"; Output; %end; %else %Do; new_var1 = "week&nextweek_count._itemfile"; new_var2 = "week&nextweek_count._vsi"; weekly_count1 = Left(Trimn(%eval(&nextweek_count.-1))); weekly_count2 = Left(Trimn(&nextweek_count.)); Output; %end; %end; %Let i = %eval(&i.+1); %end; %end; Run; %Mend Create_weekly_varlist; %Create_weekly_varlist; Many Thanks, RaviSPR.
... View more