2

If we run proc setinit in SAS we can obtain the Site Name and the Site Number.

The Site Number can be easily extracted using &syssite. Other than redirecting & parsing log output, is there a way to programmatically obtain the Site Name?

I've checked _automatic_ variables, sashelp datasets, and proc registry output to no avail.

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124

4 Answers4

3

This worked for me and didn't involve setting up the metadata server:

PROC IMPORT OUT= WORK.temp 
        DATAFILE= "D:\Program Files\SASHome\SASFoundation\9.4\core\sasinst\setinit.sss" 
        DBMS=DLM REPLACE;
        DELIMITER='3D'x; 
        GETNAMES=NO;
        DATAROW=1; 
RUN;

proc sql noprint;
     select var2 into: name
     from temp
     where var1 = 'SITEINFO NAME';
quit;

%put &name;
DCR
  • 14,737
  • 12
  • 52
  • 115
  • this didn't work for me - I tried: `"%sysget(SASHOME)/SASFoundation/&sysver/core/sasinst/setinit.sss"` which resolved to `/pub/sas/SASFoundation/9.4/core/sasinst/setinit.sss` and I got "file does not exist" (which it didn't). I tried searching for `setinit.sss` and it's not on my system, but searching for `setinit*` produced a number of files. This doesn't seem like a robust way to obtain the settings (ie, it would work on any SAS site) but maybe I'm missing something? – Allan Bowe Apr 06 '19 at 22:46
  • If there was a robust way to find that setinit file without having to use metadata that would definitely be preferable, I agree.. – Allan Bowe Apr 06 '19 at 22:49
  • do you think the sid file is on every sas site? The information is contained in there too. – DCR Apr 06 '19 at 23:03
  • I suspect you are reading a file that your administrator saved to apply the setinits. There probably isn't a consistent location or name for that file, if it even exists. – Tom Apr 06 '19 at 23:52
  • @ dcr - I don't know but again, I don't think SAS will necessarily know where it has been saved. @tom - I think you're right – Allan Bowe Apr 07 '19 at 09:03
3

Here is code to parse it from the output of PROC SETINIT.

filename out temp;
proc printto log=out; run;
proc setinit; run;
proc printto log=log; run;
data sitename;
  infile out;
  input @'Site name:' @;
  length sitename $200;
  sitename=scan(_infile_,2,"'");
  put sitename=;
  output;
  stop;
run;
Tom
  • 47,574
  • 2
  • 16
  • 29
0

With pointers from Chris Blake and FriedEgg, I ended up with this solution:

data _null_;
  length StoredText $2000 sitename $200;
  rc=metadata_getattr("omsobj:TextStore?@Name='Setinit text'"
    , "StoredText", StoredText);
  storedtext=subpad(storedtext,index(storedtext,'SITEINFO NAME=')+15);
  sitename=substr(storedtext,1,index(storedtext,"'")-1);
  put sitename=;
run;
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • That doesn't work if you aren't running metadata manager. If you are just running SAS it will pop-up a window to log into a metadata server. – Tom Apr 06 '19 at 23:34
  • For my use case this was sufficient, appreciate that not everyone has metadata though – Allan Bowe Apr 07 '19 at 21:27
0

I am guessing you are using SAS in UNIX environment because the path you wrote, then this document will helps.
Contents of the !SASROOT Directory - SAS® 9.4 Companion for UNIX Environments, Sixth Edition

Then the answer from @SCR comes in handy. As the document said

The !SASROOT directory contains the files required to use SAS 9.4.

and

If all available SAS products are installed on your system, the !SASROOT directory contains the files and directories that are listed in the following tables:

a file named "setinit.sas" is listed in the table in that link.
By the Way, I tried the answer from @SCR on my Windows machine, it works. Please also mind the path is "%sysget(SASROOT)\core\sasinst\setinit.sss".

whymath
  • 1,262
  • 9
  • 16
  • Hi @whymath - thanks for the answer, however that directory does not exist in our (unix, you are correct) system. The doc link was helpful, and it correctly states that a `setinit.sas` file exists in !SASROOT (it does), however - that file is empty. – Allan Bowe Apr 08 '19 at 10:23