Desktop productivity for business analysts and programmers

creating multiple macro variables

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 318
Accepted Solution

creating multiple macro variables

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


Accepted Solutions
Solution
‎12-11-2015 12:04 PM
Grand Advisor
Posts: 10,196

Re: creating multiple macro variables

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


All Replies
Grand Advisor
Posts: 10,196

Re: creating multiple macro variables

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;
Super Contributor
Super Contributor
Posts: 318

Re: creating multiple macro variables

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

Grand Advisor
Posts: 17,313

Re: creating multiple macro variables

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();

 

Super Contributor
Super Contributor
Posts: 318

Re: creating multiple macro variables

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. 

 

 

Solution
‎12-11-2015 12:04 PM
Grand Advisor
Posts: 10,196

Re: creating multiple macro variables

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;
Super Contributor
Super Contributor
Posts: 318

Re: creating multiple macro variables

Thanks Ballardw and Reeza....

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 517 views
  • 5 likes
  • 3 in conversation