Monday, November 13, 2017

SAS: A connection Server "Local" could not be established

From SAS Support, Nov 13 2017:




>>>   A connection Server "Local" could not be established


Probably just need to register sas.  

Here are the steps:

1. close EG, close SAS
2. click Start > then type:  cmd
3. you will see cmd.exe at the top of the window, then right-click on cmd.exe and choose Run as Administrator
4. from the dos window type:  cd ..    then enter, then type again:  cd ..  then enter  ( that puts you at the c:  prompt)
5. then enter:  cd program files  
6. then enter: cd sashome
7. then enter: cd sasfoundation
8. then enter: cd 9.4  
9. then enter:  sas /regserver      (there is a space between 'sas'   and the forward slash)

no error should occur.

10. now, start EG and make sure you can connect to Local server and open data and run code/tasks, etc.




Thursday, September 28, 2017

SAS: Exporting XML to Excel, missing ApnDatabase.xml file




I got an error message "ApnDatabase.xml not found". It has something to do with exporting XML to XLS. Turns out my ApnDatabase.xml did, in fact, exist in C:\Windows\System32. After much headbanging I found an obscure note on the web that said if you are using Windows 10 then ApnDatabae.xml needs to be in C:\Windows\SysWOW64. I copied the file from System32 to SysWOW64 and restarted my machine and it worked.



Tuesday, September 26, 2017

SAS: ERROR: Insufficient authorization to access C:\Windows\system32\sasgraph.jpg



Edit 2017-12-05.

Was all that (below) really necessary?
I think I might have just been missing

ODS GRAPHICS ON;
GOPTIONS RESET=ALL border hsize=14in vsize=8in;



_____________________________________________________________________________




Re: ERROR: Insufficient authorization to access C:\Windows\system32\sasgraph.jpg




Hello Bill,

This is in regard to SAS tracking number 7612237223, where in your last email to this track, you wrote:

>At this point I really don’t care how or where the graph is created: I just want the code (which I inherited) to run. If you look at the source, it’s clear that the code is generated from an EG wizard. And yet it has this error. I see this error throughout this particular EG project. Have Googled it. This helped in SOME cases, but not this one.

If you are submitting actual code to SAS via Enterprise Guide, modify the following statements in the code:

ODS _ALL_ CLOSE;
GOPTIONS RESET=ALL;
OPTIONS DEV=PNG;
GOPTIONS XPIXELS=0 YPIXELS=0;
GOPTIONS ACCESSIBLE;
ODS OUTPUT;
ODS GRAPHICS ON;
ODS LISTING GPATH="%sysfunc(getoption(WORK))";

So that they now look like this:

ODS _ALL_ CLOSE;
ODS LISTING;

FILENAME GRAFOUT  "%sysfunc(pathname(work))/sasreport.png";

GOPTIONS RESET=ALL DEVICE=PNG GSFNAME=GRAFOUT;


As you can see, Enterprise Guide adds a lot of extra statements to the code that are not actually needed.  The statements above will allow the code to run fine and will write the PNG graph file to the temporary SAS WORK location.  Instead, if you prefer to right the graph to a permanent directory on your hard drive, replace  %sysfunc(pathname(work))  above with an actual existing directory on your hard drive, such as:

FILENAME GRAFOUT  "C:/Temp/sasreport.png";

Regards,


SAS Technical Support
http://www.sas.com
http://support.sas.com

SAS ... THE POWER TO KNOW







Monday, September 11, 2017

SAS: Write value of a macro variable to log

Whenever I need to write the value of a macro variable to the SAS log, I do the following

%put MACVAL=&MACVAL;

Well, according to http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n189qvy83pmkt6n1bq2mmwtyb4oe.htm, the same thing can be done as follows:

%put &=MACVAL;





Monday, August 21, 2017

SAS: Create SAS column name from a string field


SAS: Create SAS column name from a string field



%macro var_name_from_string(input=);
%* make a SAS variable name from a string ;
%* 1. keep numeric, alpha, underscore, and blanks ;
%* 2. replace multiple blanks with a single blank ;
%* 3. remove trailing blanks ;
%* 4. convert remaining blanks to underscore ;
%* 5. limit to 20 characters so I can prepend prefix such as dmy_acct_;
substr(translate(left(compbl(compress(strip(&input), "", "NSK"))), "_", " "),1,20)
%mend var_name_from_string;


data work.test;
attrib s length=$50;
s = %var_name_from_string(input="ABCDE"); output;
s = %var_name_from_string(input="AB CDE"); output;
s = %var_name_from_string(input="AB(C)DE  "); output;
s = %var_name_from_string(input="AB C_D!E"); output;
run;



proc sql noprint;
create table work.catgys as
select distinct KEY_CATGY
, %var_name_from_string(input=key_catgy) as CATGY_DMY
from &MY_TABLE
;
quit;
run;



data _null_;
set work.catgys end=eof;
call symput("catgy" || trim(left(_n_)), KEY_CATGY);
call symput("catgydmy" || trim(left(_n_)), CATGY_DMY);
if (eof) then do;
      call symput("catgys", trim(left(_n_)));
end;
run;



%macro create_dummy_fields;
data &MY_TABLE_DMY;
set &MY_TABLE;
%do i = 1 %to &CATGYS;
      dmy_catgy_&&CATGYDMY&i = (KEY_CATGY = "&&CATGY&i");
%end;
run;

%mend create_dummy_fields;

%create_dummy_fields;