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

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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