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

Full disclosure, I was trained on SAS EG, and am not a fully fledged programmer.

 

I work for a college, and am in charge of the daily enrollment reports. I am trying to automate these reports using INTNX and SYMPUT, but am stumbling over the date format in SYMPUT.

 

The enrollment reports are compared this year to last, but the dates being compared changes from year to year. The main date change is the 'census' date (census date is when students can no longer drop classes).  The enrollment reports compare 'yesterday' to 'this day last year that is the same number of days from census'. Example I want to compare yesterday 03Mar2016 to last year but there are -7 days difference from the census date. So comparing the info of 03Mar2016 to 29Apr2015.

 

The problem I am having is that the code below runs, without errors, but then when I run the whole program, errors start piling up. I've narrowed the problem to the date format for "Priorname2". In that SYMPUT, date9. will not work, and sasdate. only works when the first part (the code shown) runs, not when the data steps are included.

 

What can I do to get this time last year, -7 days?

 

Here is the code I am using to try and automate my report:

 

options pageno=1 ;

libname COURSE 'K:\Course\SP16\';RUN;
libname COURSE2 'K:\Course\SP15\';RUN;
%LET SEM1 = SP16; RUN;
%LET SEM2 = SP15; RUN;
DATA _NULL_;
      Yesterday1 = INTNX('day',today(),-1,'Same');
      CALL SYMPUT("PriorDateName", PUT(Yesterday1,date9.));
      Last_Year = INTNX('year',today(),-1,'Same');
      CALL SYMPUT("PriorName2", PUT(Last_Year, sasdate.));
	  Last_Yr_Before_Cen = INTNX('day',"&PriorName2",-4,'Same');
      CALL SYMPUT("Prior", PUT(Last_Yr_Before_Cen,date9.));

PUT "&PriorDateName";
PUT "&PriorName2"; /*this is a sas date format, used because date9. format was not recognized by the synput function*/
PUT "&Prior";
RUN;

 

 

Thank you for any input,

Renee

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

SAS stores dates as integers, with each day being one greater than the day before.  So you should be able to get the date you want more directly:

 

data _null_;

Last_Year = intnx('YEAR', today(), -1, 'Same') - 4;   /* or perhaps -7 if that's what you really want */

 

Then transfer that value in the same DATA step:

 

call symputx('Prior', put(last_year, date9.));

run;

 

The problems may be arising later, because you need to refer to dates with the proper syntax.  This would be one way to use &PRIOR using the proper SAS syntax to refer to a date:

 

"&prior"d

 

It's possible your later code omits the "d" at the end.

View solution in original post

5 REPLIES 5
ballardw
Super User

I am not aware of a format SASDATE. so cannot tell what you may be attempting to do with this line:

CALL SYMPUT("PriorName2", PUT(Last_Year, sasdate.));

 

Also it is generally not going to work referencing a macro variable in the same data step that creates it so this would fail in general:

 

  Last_Yr_Before_Cen = INTNX('day',"&PriorName2",-4,'Same');

 

I think you may be looking for:

 

  Last_Yr_Before_Cen = INTNX('day',last_year,-7,'Same');

 

How do you want the values for your macro variables to appear assuming you ran that code on April 4 2016?

 

__Renee__
Fluorite | Level 6
Thank you for your help!
Astounding
PROC Star

SAS stores dates as integers, with each day being one greater than the day before.  So you should be able to get the date you want more directly:

 

data _null_;

Last_Year = intnx('YEAR', today(), -1, 'Same') - 4;   /* or perhaps -7 if that's what you really want */

 

Then transfer that value in the same DATA step:

 

call symputx('Prior', put(last_year, date9.));

run;

 

The problems may be arising later, because you need to refer to dates with the proper syntax.  This would be one way to use &PRIOR using the proper SAS syntax to refer to a date:

 

"&prior"d

 

It's possible your later code omits the "d" at the end.

__Renee__
Fluorite | Level 6

Thank you! I was able to drop that into my program and it worked!

ngio
Calcite | Level 5

i tend to do this

 

%let prior=%sysfunc(intnx(day,%sysfunc(intnx(year,"&sysdate"d,-1,s)),-4),date9.);

 

"&prior."d

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 10452 views
  • 2 likes
  • 4 in conversation