DATA Step, Macro, Functions and more

Global Variable Dynamic Assignments

Reply
N/A
Posts: 0

Global Variable Dynamic Assignments

Hi All,

I have been given an opportunity to automate filename assignments for multiple input text files. (Our current "work around" is to manually update every month).

We are using SAS 8.2 in a Windows XP environment.

We have a monthly SAS program that has a "rolling" 18 month set of input files.
So, each month the oldest file (18th) from the previous month rolls off.
We run this process the first week, following the previous month end.
I would like some help in dynamically assigning the 2 character Month and 2 character Year, within the filepath.

I would also like the ability to dynamically assign the Server name, based on the Server the SAS program is executing (Prod = awappp23, Test = dwappt23, Dev = dwappc23); if possible.

Here are the existing FileName references used for September 2008 Monthend:
filename ACN1F19 '\\awappp23\f\report store\sasdata\four_0307.TXT';
filename ACN1F18 '\\awappp23\f\report store\sasdata\four_0407.TXT';
filename ACN1F17 '\\awappp23\f\report store\sasdata\four_0507.TXT';
filename ACN1F16 '\\awappp23\f\report store\sasdata\four_0607.TXT';
filename ACN1F15 '\\awappp23\f\report store\sasdata\four_0707.TXT';
filename ACN1F14 '\\awappp23\f\report store\sasdata\four_0807.TXT';
filename ACN1F13 '\\awappp23\f\report store\sasdata\four_0907.TXT';
filename ACN1F12 '\\awappp23\f\report store\sasdata\four_1007.TXT';
filename ACN1F11 '\\awappp23\f\report store\sasdata\four_1107.TXT';
filename ACN1F10 '\\awappp23\f\report store\sasdata\four_1207.TXT';
filename ACN1F09 '\\awappp23\f\report store\sasdata\four_0108.TXT';
filename ACN1F08 '\\awappp23\f\report store\sasdata\four_0208.TXT';
filename ACN1F07 '\\awappp23\f\report store\sasdata\four_0308.TXT';
filename ACN1F06 '\\awappp23\f\report store\sasdata\four_0408.TXT';
filename ACN1F05 '\\awappp23\f\report store\sasdata\four_0508.TXT';
filename ACN1F04 '\\awappp23\f\report store\sasdata\four_0608.TXT';
filename ACN1F03 '\\awappp23\f\report store\sasdata\four_0708.TXT';
filename ACN1F02 '\\awappp23\f\report store\sasdata\four_0808.TXT';
filename ACN1F01 '\\awappp23\e\report store\sasdata\four_0908.TXT';

I can get the current date from the system, but how do I perform arithmetic to subtract the Month and Year values for each preceeding filename?
Any Ideas??
Respected Advisor
Posts: 3,799

Re: Global Variable Dynamic Assignments

Posted in reply to deleted_user
You can use INTNX function and MMYYN format. You could also use FILENAME function in the same data step to allocate the file name instead of writing FILENAME statements.


[pre]
data _null_;
today=today();
length path $256 fileref $8;
do i = 19 to 1 by -1;
prev = intnx('MONTH',today,-i);
path = cats('\\awappp23\f\report store\sasdata\four_',put(prev,mmyyn4.),'.TXT');
fileref = cats('ACN1F',put(i,z2.));
put 'NOTE: ' fileref path;
rc = filename(fileref,path);
end;
run;
filename _all_ list;
[pre]
N/A
Posts: 0

Re: Global Variable Dynamic Assignments

Posted in reply to deleted_user
Great suggestion.

Do you have any response to my other need?
(I would also like the ability to dynamically assign the Server name, based on the Server the SAS program is executing (Prod = awappp23, Test = dwappt23, Dev = dwappc23); if possible.)

Can I retrieve the Server Name from some System Variable??
Respected Advisor
Posts: 3,799

Re: Global Variable Dynamic Assignments

Posted in reply to deleted_user
This version uses the windows COMPUTERNAME environment variable. I don't know if that would be server name. Open a command prompt and type "SET" to see all the env variables. There should be one that is server name.

Then use SYSGET to retrieve the value in SAS.

[pre]
data _null_;
today=today();
server = sysget('COMPUTERNAME');
length path $256 fileref $8;
do i = 19 to 1 by -1;
prev = intnx('MONTH',today,-i);
path = cats('\\',server,'\f\report store\sasdata\four_',put(prev,mmyyn4.),'.TXT');
fileref = cats('ACN1F',put(i,z2.));
put 'NOTE: ' fileref path;
rc = filename(fileref,path);
end;
run;
filename _all_ list;

[pre]
N/A
Posts: 0

Re: Global Variable Dynamic Assignments

Posted in reply to deleted_user
Looks like the 'Cats' and 'Filename' functions are not available in my version (8.2). I can use Compress with Concat Pipes.
How can I assign the dynamically created path value to the Filename reference or Infile
Respected Advisor
Posts: 3,799

Re: Global Variable Dynamic Assignments

Posted in reply to deleted_user
You did say 8.2, sorry about that. You can replace cats with || plus compress and or trim. Filename since V6.12 so that is not a problem. Once you get FILEREF and PATH constructed correctly FILENAME function should work.

Did you find the server name?
N/A
Posts: 0

Re: Global Variable Dynamic Assignments

Posted in reply to deleted_user
I had something else set up incorrectly....Now it all works as recommended.
Kudos!!
Ask a Question
Discussion stats
  • 6 replies
  • 166 views
  • 0 likes
  • 2 in conversation