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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 891 views
  • 0 likes
  • 3 in conversation