BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Barite | Level 11 woo
Barite | Level 11

Hello, can someone please help me to create macro variables for dates (in format 09Dec15) from today-2 to last year same date? 

 

so like i want to create macro variable 

date1 which would resolve to 07Dec14

date2=08Dec14

date3=09Dec14

.

.

.

date366=07Dec15

 

 

Thank you....

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

For that comparison you do not need any macro variables, just a data set with the target dates and then compare.

 

data basedates;
   start = '07DEC2014'd;
   do date=start to (intnx('year',Start,-1,'Same') ) by -1;
      output;
   end;
   drop start;
   format date date9.;
run;

proc sql;
   title "Dates in base not occurring in comparison set";
   select date from basedates
   except
   select distinct date from comparison;
quit;

View solution in original post

6 REPLIES 6
ballardw
Super User

This does what you've asked.

data _null_;
   start = '07DEC2014'd;
   do date=start to (intnx('year',Start,-1,'Same') ) by -1;
      name=cats('date',start-date+1);
      call symputx(name,put(date,date7.));
   end;
run;
woo
Barite | Level 11 woo
Barite | Level 11

Thank You Ballardw, but not sure how it creartes 366 macro variables, date1 to date366, which would resolves to 07dec14 to 07dec15. 

 

Also, i want to create this everyday, so tomorrow, 366 macro variables, date1 to date366, supposed to resolve to 08dec14 to 08dec15

 

 

thanks for your time....

Reeza
Super User

I question what you're doing downstream with this, I feel that there's likely a better way. 

You can adjust @ballardw code by changing the start to

 

start=today();

 

woo
Barite | Level 11 woo
Barite | Level 11

I have one sas dataset wich has last 1 yr history data in it and it used to gets update on daily bases. some times we miss some date data in it. so i want to know which date has missed in b/w.

 

to do that i am thinking to create macro variable everyday for last 1 year and check against distinct date from that history dataset. 

 

 

ballardw
Super User

For that comparison you do not need any macro variables, just a data set with the target dates and then compare.

 

data basedates;
   start = '07DEC2014'd;
   do date=start to (intnx('year',Start,-1,'Same') ) by -1;
      output;
   end;
   drop start;
   format date date9.;
run;

proc sql;
   title "Dates in base not occurring in comparison set";
   select date from basedates
   except
   select distinct date from comparison;
quit;
woo
Barite | Level 11 woo
Barite | Level 11

Thanks Ballardw and Reeza....

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 2447 views
  • 5 likes
  • 3 in conversation