Category Archive ‘Uncategorized‘

 
 

Current Working Folder in SAS

whereamI

The concept of current working directory in SAS is not as important as it sounds. Most SAS users point to file reference (fileref) and library reference (libname, a “namespace”-like mechanism to access files ), which are much convenient in large project with multiple folders.

Sometimes I push files to the current folder in relatively small task because I don’t want to

  • jump to C:UsersjhuappdataLocalTempSAS Temporary Files_TD2820_like folder to get the temporary datasets (in WORK library)
  • hard code a folder to receive ODS outputs.

The demo codes(a SAS system autocall macro %xlog used):

/*display current directory in LOG window*/
%xlog(cd);

/*change current working directory */
x "cd a:test";

/*display current directory in LOG window*/
%xlog(cd);

/*output a dataset in current directory */
data "iris";
    set sashelp.iris;
run;

/*output a pdf file in current directory */
ods pdf file="iris.pdf";
proc print data="iris";
run;
ods pdf close;

/*show files in current directory */
%xlog(dir);

And the LOG window may like:

Path
—-
C:Usersjhu

Path
—-
A:test

    Directory: A:test
Mode        LastWriteTime   Length Name
—-        ————-   —— —-
-a— 10/8/2012  12:49 PM   113665 iris.pdf
-a— 10/8/2012  12:49 PM    13312 iris.sas7bdat

NOTES:

  • You can get autocall macro %xlog in (if SAS 9.3 in Windows 7)

C:Program FilesSASHomeSASFoundation9.3coresasmacro

An equivalent macro %xlst generates the shell command outputs to LIST window.

  • If prefer Windows Powershell, a similar macro can be used (put it to autocall if needed):

%macro pslog(cmd);
  option nonotes;
  filename pslogcmd pipe "powershell &cmd";
  data _null_;
     file log;
     infile pslogcmd;
     input;
     put _INFILE_;
  run;
  option notes;
%mend pslog;

Test the following commands:

%pslog(gl);
%pslog(get-location);
%pslog(get-host)

GitHub and Weekend Programming

Yihui of Iowa State just texted me that GitHub is programmers’ Facebook. Inspired by him(great thanks!), I also begin to play with GitHub now:

https://github.com/Jiangtang

Currently I only created one repo as personal SAS code repository. To kill weekend time, I uploaded piece of codes to count the OpenCDISC validation rules by models. To use it:

filename CDISC url “https://raw.github.com/Jiangtang/Programming-SAS/master/Rules_Count_OpenCDISC_XML.sas”;

%include CDISC;

%Rules_Count_OpenCDISC_XML(dir=C:tempOpenCDISCsoftwareopencdisc-validatorconfig)

while get:

OC_by_model

Happy weekend and happy programming.