- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-05-2021 06:11 PM
(1428 views)
I am trying to Replicate below sas code dates into python or pyspark. below is the code.
/******Date code****************************/
/*Below, created a variable named as Start_date and passed value 01Dec2020.*/
%let start_date = 01Dec2020;
/*Below, here I am creating automated different date variables or columns.*/
data _null_;
call symputx('table_dt',strip(put(month("&start_date."d),z2.))||strip(year("&start_date."d)));
call symput ('word_dt',"&start_date.");
call symput ('prev_year',put(intnx('year',"&start_date."d,-1,'s'),date9.));
call symput ('sasdt0',put(intnx('month',"&start_date."d,1),date9.));
call symput ('tddt0', "'"|| put(intnx('month',"&start_date."d,1),yymmdd10.)||"'");
call symput ('tdend', "'"|| put(intnx('month',"&start_date."d,0,'e'),yymmdd10.)||"'");
do i = 1 to 7;
call symputx (cats('sasdt',i),put(intnx('month',"&start_date."d,-(i-1)),date9.));
call symputx (cats('tddt',i),"'"||put(intnx('month',"&start_date."d,-(i-1)),yymmdd10.)||"'");
end;
run;
/printing below calculated variables which is getting used to extract data from teradata and just below theirs output/
%put &sasdt0. &tddt0.;
01JAN2021 '2021-01-01'
%put &sasdt1. &tddt1.;
01DEC2020 '2020-12-01'*/
%put &sasdt2. &tddt2.;
01NOV2020 '2020-11-01'*/
%put &sasdt3. &tddt3.;
01OCT2020 '2020-10-01'*/
%put &sasdt4. &tddt4.;
01SEP2020 '2020-09-01'*/
%put &sasdt5. &tddt5.;
01AUG2020 '2020-08-01'*/
%put &sasdt6. &tddt6.;
01JUL2020 '2020-07-01'*/
%put &sasdt7. &tddt7.;
01JUN2020 '2020-06-01'*/
%put table date is &table_dt. and word date is &word_dt.;
table date is 122020 and word date is 01Dec2020;
%put prev year is &prev_year.;
prev year is 01DEC2019
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It seems to me that this question would be better asked on a python forum.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Creating macro variable is kinda SAS specific.
And it's not the end goal, which is how you intend you use these macro variabels?
Agree with @ChrisNZ, this suites a Python forum better.
Data never sleeps