SAS Programming

DATA Step, Macro, Functions and more
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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1429 views
  • 0 likes
  • 3 in conversation