BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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??
6 REPLIES 6
data_null__
Jade | Level 19
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]
deleted_user
Not applicable
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??
data_null__
Jade | Level 19
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]
deleted_user
Not applicable
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
data_null__
Jade | Level 19
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?
deleted_user
Not applicable
I had something else set up incorrectly....Now it all works as recommended.
Kudos!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 826 views
  • 0 likes
  • 2 in conversation