I am trying to run some SAS program to query a Oracle DB on SAS EG 9.3. The moment I run the code, I get this red underline and number 49. It doesn't even say "Error" to suspect some syntax errors. Below is a screenshot. Can anyone please help me resolve this issue.
A few lines of the code which gives this error:
%macro pre_network_roll(start);
%let start=%sysfunc(inputn(&start,anydtdte9.));
%let date=%sysfunc(putn(%sysfunc(intnx(month,&start,0,e)),date9.));
Related
When using R markdown for making statistical reports, I have the ability to echo the R code in my output document. I'm learning SAS and I was wondering if it was possible to highlight or echo the SAS code in my final ODS report ? I'm using a dirty hack right know to display the code in my document, which is using "ods text = ", but it seems quite redundant. Plus it doesn't add syntax highlighting.
That feature does not exist in the SAS language right now, but it has been mentioned in several talks by Amy Peters, principal product manager of the SAS programing environments, as a planned feature for a near-future SAS release (with no specific date yet, but hopefully in the next 2 years). It would likely be implemented in a similar fashion to Jupyter Notebooks, in that you write your code and get your output inline.
That said, SAS does support Jupyter Notebooks, which is the best current (third party) solution. Contact your SAS administrator for more information.
I have an idea here, I'm the type of guy who dosent take no for answer and find a way to fiddle and get it done... but i think this is abit far fetch... you can try still I think it will work with mostly evrything but may have a hard time to play with quotes when you have multiple semi colomns....
Check:
I started by creating a dumbass dataset :
data tata;
x=1;
run;
then we do the following:
%let code= select * from tata;
proc sql;
create table report as
&code.;
quit;
proc print data=report;
footnote "&code.";
run;
The rationale:
I think it you put your code in macrovariables and then execute those macro variables you would be able to print show the code after by printing the macrovariable following your text...
See the sample
Hopefully someone out there will have run into this before. I'm trying to use the street level geocoding capability of SAS' PROC GEOCODE, but I keep getting a cryptic error. I couldn't find anything on the net about it (although to be fair I only spent a half hour looking).
First, I'm using SAS Enterprise Guide (I've tried on both v4.2 and v4.3), although I still prefer to program as I find the point and click interface quite limiting. Maybe this right here is my problem?
Anyway I first get the lookup data sets from http://support.sas.com/rnd/datavisualization/mapsonline/html/geocode.html and follow the instructions in the readme. I also use the pre-written SAS program to import the CSV files. My input dataset contains just 4 variables: street address, city, state, and zip. I then run the following code:
libname josh 'C:\Users\Josh\Desktop\Geocode\SAS files';
proc geocode
method=street
data=SASUSER.Home_Policy_Address_Detail
lookupstreet=josh.USM
out=test;
run;
However I get this error:
ERROR: Variable NAMENC not found in JOSH.USM data set.
Nowhere in the readme or the import program is a variable named "NAMENC" ever mentioned. This is what has me stumped. Is it something wrong with the simple PROC GEOCODE program I wrote? Is it due to me using SAS EG (although I've yet to run into a base SAS procedure that hasn't worked on EG)? Or something else?
Any help/guidance would be much appreciated. Thanks in advance!
Check your SAS version. You can use the 'Help' menu in DMS mode or submit this statement:
%put &sysvlong;
It looks like you are using SAS 9.3 but your lookup data JOSH.USM is the lookup data formatted for SAS 9.4.
PROC GEOCODE street lookup data comes in two slightly different formats, one for SAS 9.3 and another for 9.4. When you download the nationwide lookup data from the SAS MapsOnline geocoding page, make sure to download the version appropriate for your SAS release.
I suddenly got an error message when exporting from SAS to Excel. I've been using the code below.
libname xls excel '..\Test.xlsx' ver=2007;
proc datasets lib = xls nolist;
delete Sweden;
quit;
data xls.Sweden;
set WORK.falcon_cases_2;
run;
libname xls clear;
This is what the log says:
NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.
ERROR: Execute: Unable to insert row
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 4865 observations read from the data set WORK.FALCON_CASES_2.
WARNING: The data set XLS.Sweden may be incomplete. When this step was stopped there were 4864
observations and 14 variables.
ERROR: ROLLBACK issued due to errors for data set XLS.Sweden.DATA.
That's the error message I got. I've googled the error message and it seems like it usually indicates that the data set contains to many rows for Excel, 65 000 something. The data set I'm trying to export is only about 5500 rows.
Thanks for your help!
Things I would look into:
Funny characters. Excel might have had a transcoding problem if there are unicode characters in the data that don't transcode properly to wlatin1 (or whatever your default encoding is for Windows).
Disk space. Did your disk run out of space while running this?
Network or disk corruption. Is this replicable (does it occur if you try again)?
Can you try running that code on a basic dataset, like sashelp.class? Does that still cause the problem?
I use SAS proc sql execute statement to run sql and access tables on Oracle server. In order to let the script run automatically, I normally drop tables or indice before creating them. Sometimes however, when the drop sql code runs, the table or index doesn't exist. An error message will be logged in SAS about dropping something that doesn't exist. But since the SAS code will continue after the drops, this kind of error message doesn't matter at all. I want to suppress these error messages, stop SAS from logging them because I don't care about them. How can I do this in proc sql?
Thanks for any help.
I'm not aware of an option to supress this single type of error. There are a couple of options though.
The best bet is to clean up your code so you check to see if the data set exists before trying to act on it:
%if %sysfunc(exist(&name_of_data_set)) %then %do;
You could also redirect all logging during these steps where you get messages you don't want with proc printto, but you would potentially lose valuable information.
Executing locally in a clean session:
%let x = %str(put(age, best.));
proc sql;
select &x from sashelp.class;
quit;
This generates the following error:
1 put(age, best.)
----
22
----
76
ERROR 22-322: Syntax error, expecting one of the following: a format name, ?.
ERROR 76-322: Syntax error, statement will be ignored.
But this "manually-resolved" version runs without notes, warnings or errors:
proc sql;
select put(age, best.) from sashelp.class;
quit;
Can somebody explain exactly what %str() is doing in this program that causes an issue at execution time? Apologies for the vague question, but I am unsure what the relevant interactions are; I cannot replicate using equivalent data-step syntax so perhaps proc SQL peculiarities are involved?
The %str() function masks a character string during macro compilation. Remove the %str() function in the let statement or add an %unquote() function in the sql select to have if resolve correctly.
Answered at this question on runsubmit.com:
I'm going to mark this answer as
correct because it led me to this page
of documentation:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#tw3514-unquote.htm
- "In rare cases, masking text with a macro quoting function changes the way
the word scanner tokenizes the text
... The word scanner does not use it
as the boundary of a literal token in
the input stack". Sounds like a bug,
frankly, but if the tokenizer
algorithm is as ancient and hairy as I
imagine, I'd spin it as a quirk too!
Can you use a format statement instead? For example, this works just fine.
%let x = %str( age format=best.);
proc sql;
select &x. from sashelp.class;
quit;
For some reason SAS doesn't like the "best." format.
i.e. when I try this, your code works
%let x = %str(put(age, 8.));
????
If you add this to your code
%put _user_ ;
you will see how &x is quoted by %str, in the log. That is why the proc sql code doesn't work. Using %Unquote in the select portion of the proc sql statement will allow the code to run.
http://www2.sas.com/proceedings/forum2007/152-2007.pdf