DATA Step, Macro, Functions and more

Simplify and clarify your fileref statements.

Reply
N/A
Posts: 0

Simplify and clarify your fileref statements.

I got tired of defining my filerefs and having them run off the right side of the Enhanced editor, especially when the really important stuff was at the end of that string. Using several ideas provided by Joe Flynn at SAS Technical Support, I came up with the following solution.

On my Windows XP machine, the %USERPROFILE% environment variable is set to:
C:\Documents and Settings\{username}
and the default SASV9.CFG file sets SASUSER to:
C:\Documents and Settings\{username}\My Documents\My SAS Files\9.1

I create two macro variables, &mydocs and &mypath, every time SAS starts by using the following lines in the AUTOEXEC.sas file:

%let mydocs=%sysget(USERPROFILE)\My Documents ;

proc sql noprint ;
select path into :mypath from dictionary.members
where libname='SASUSER' and memname='PROFILE' ;
quit ;


This gives me the following variables:
&mydocs resolves to C:\Documents and Settings\{username}\My Documents
&mypath resolves to C:\Documents and Settings\{username}\My Documents\My SAS Files\9.1

Now my filerefs are short and simple for things in My Documents and look like:
filename WIDGETS "&mydocs\widgets.txt" ;

And my PROC EXPORT OUTFILE= statement looks like:
OUTFILE= "&mypath\Data\USA State Codes".

I hope this example will get you started learning about %sysget and the dictionary tables.
Ask a Question
Discussion stats
  • 0 replies
  • 104 views
  • 0 likes
  • 1 in conversation