BookmarkSubscribeRSS Feed
ManoharNath
Obsidian | Level 7

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
ChrisNZ
Tourmaline | Level 20

It seems to me that this question would be better asked on a python forum.

LinusH
Tourmaline | Level 20

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1195 views
  • 0 likes
  • 3 in conversation