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

Hi,

 

 

 

I am trying to update this program I use, by automating the variables referring to dates.

 

I have managed to get all the dates in the format I want but now I would like to be able to call them during the program.

 

ThisDate= Date();  

   FirstDayOfMonth = IntNX("Month", ThisDate, 0);       
   FirstDayOfLastMonth = IntNX("Month", ThisDate, -1);  
   StudyStart = IntNX("Month", ThisDate, -12);            
   StudyEnd = IntNX("Month", ThisDate, 0)-1;
   OneYearAgo = IntNX("Month", ThisDate, -12); 
   date_strt = IntNX("Month", ThisDate, -15);
   date_end = IntNX("Month", ThisDate, -3)-1;
   currentyear = YEAR(FirstDayOfLastMonth);
   curntyear = YEAR(FirstDayOfLastMonth)-2000;
   monthclsng = (MONTH(FirstDayOfLastMonth));
   FirstDayOfYear = IntNX("Year", ThisDate, 0);




 format ThisDate DDMMYY.;
 format FirstDayOfMonth YYMMDDN6.;
 format FirstDayOfLastMonth YYMMDDN6.;
 format OneYearAgo YYMMDDN6.;
 format StudyStart YYMMDDN8.;
 format StudyEnd YYMMDDN8.;
 format date_strt YYMMDDN8.;
 format date_end YYMMDDN8.;
 format monthclsng Z2.;
 format FirstDayOfYear YYMMDDN6.;

I am using SAS 9.3.

 

Thank you in advance. 🙂 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

To accomplish that, replace all the FORMAT statements in the DATA step.  Instead of adding a format, transfer the value to a macro variable.  For example, you have:


 format ThisDate DDMMYY.;
 format FirstDayOfMonth YYMMDDN6.;
 format FirstDayOfLastMonth YYMMDDN6.;

Replace that with:

call symputx('ThisDate', put(ThisDate,DDMMYY.));
call symputx('FirstDayOfMonth', put(FirstDayOfMonth, YYMMDDN6.));
call symputx('FirstDayOfLastMonth', put(FirstDayOfLastMonth, YYMMDDN6.));

There's an assumption here that the formatted values will make sense when substituted into your program later.

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

At least give us clue how/ where you want to use these values.

In a single data set then use the data step code you show. Elsewhere we really need to know how you want to use them.

 

 

Astounding
PROC Star

Other possibly important questions:

 

What's the name of the data set holding these variables?

 

Does it contain just one observation, or more than one?

 

AdiBoo
Calcite | Level 5

Hi,


Thanks for those answers, I indeed could have been a bit more specific.

The finality was to feed the values in that particular format into the following parameters that are use throughout the program.

 

I've inserted more code below, adding on what I previously sent.

 

 

 

 

   

data datez ;


   ThisDate= Date();  

   FirstDayOfMonth = IntNX("Month", ThisDate, 0);       
   FirstDayOfLastMonth = IntNX("Month", ThisDate, -1);  
   StudyStart = IntNX("Month", ThisDate, -12);            
   StudyEnd = IntNX("Month", ThisDate, 0)-1;
   OneYearAgo = IntNX("Month", ThisDate, -12); 
   date_strt = IntNX("Month", ThisDate, -15);
   date_end = IntNX("Month", ThisDate, -3)-1;
   currentyear = YEAR(FirstDayOfLastMonth);
   curntyear = YEAR(FirstDayOfLastMonth)-2000;
   monthclsng = (MONTH(FirstDayOfLastMonth));
   FirstDayOfYear = IntNX("Year", ThisDate, 0);




 format ThisDate DDMMYY.;
 format FirstDayOfMonth YYMMDDN6.;
 format FirstDayOfLastMonth YYMMDDN6.;
 format OneYearAgo YYMMDDN6.;
 format StudyStart YYMMDDN8.;
 format StudyEnd YYMMDDN8.;
 format date_strt YYMMDDN8.;
 format date_end YYMMDDN8.;
 format monthclsng Z2.;
 format FirstDayOfYear YYMMDDN6.;

run ;


/* parameters*/

%let base_polvig  = &FirstDayOfMonth    ;      
%let base_polvig_old  = &FirstDayOfLastMonth   ;     
%let base_polvig_old1  = &FirstDayOfYear   ;  
%let base_polvig_old_old  = &OneYearAgo    ; 		
%let annee = &currentyear ; 
%let an   = &curntyear ;
%let mois = &monthclsng ; 
%let deb_etude = &StudyStart ;   
%let fin_etude = &StudyEnd ;  
%let date_deb1 = &date_strt ;   
%let date_fin1 = &date_end;    


 

Thanks 🙂 

Astounding
PROC Star

To accomplish that, replace all the FORMAT statements in the DATA step.  Instead of adding a format, transfer the value to a macro variable.  For example, you have:


 format ThisDate DDMMYY.;
 format FirstDayOfMonth YYMMDDN6.;
 format FirstDayOfLastMonth YYMMDDN6.;

Replace that with:

call symputx('ThisDate', put(ThisDate,DDMMYY.));
call symputx('FirstDayOfMonth', put(FirstDayOfMonth, YYMMDDN6.));
call symputx('FirstDayOfLastMonth', put(FirstDayOfLastMonth, YYMMDDN6.));

There's an assumption here that the formatted values will make sense when substituted into your program later.

 

 

AdiBoo
Calcite | Level 5

Thanks a lot @Astounding !

I've had time to finish up and the call symputx function works ! 🙂 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1351 views
  • 1 like
  • 3 in conversation