I am a beginner level programmer in SAS and I am running into some issues trying to do LR.
I am trying to run a multivariate linear regression on a dataset (ads.csv, predicting sales based on the TV, radio, and newspapers figures)
S_no,TV,Radio,Newspaper,Sales
1,230.1,37.8,69.2,22.1
2,44.5,39.3,45.1,10.4
3,17.2,45.9,69.3,9.3
4,151.5,41.3,58.5,18.5
However when I run the linear regression in SAS using the initial coded to declare the output data, I get an error that saying : ERROR: Output SAS data set must be provided.
options linesize=180 pagesize=180 nodate pageno=1;
libname Linreg1 "/folders/myfolders";
proc import datafile="/folders/myfolders/ads.csv";
out=Linreg1.output dbms=dlm replace;
delimiter=,;
getnames=yes;
run;
Following is the complete log of this small piece of code :
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 options linesize=180 pagesize=180 nodate pageno=1;
57 libname Linreg1 "/folders/myfolders";
NOTE: Libref LINREG1 was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders
58 proc import datafile="/folders/myfolders/ads.csv";
ERROR: Output SAS data set must be provided.
NOTE: The SAS System stopped processing this step because of errors.
Any help would be greatly appreciated!
[Edit: as Reeza said in that first comment] There are extra semicolons in there - your proc import line needs to read as below:
options linesize=180 pagesize=180 nodate pageno=1;
libname Linreg1 "/folders/myfolders";
proc import datafile="/folders/myfolders/ads.csv" out=Linreg1.output dbms=dlm replace;
delimiter=,;
getnames=yes;
run;
Related
I want to export multiple SAS datasets as CSV files (not as xlsx files) using SAS 9.4. When using the code for any of the datasets:
proc export data = dataset
outfile = "C:\MBorg\dataset.csv"
dbms = csv replace;
run;
I receive this error message:
ERROR: Export unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.06 seconds
cpu time 0.01 seconds
Contrary to what the error message suggests, the SAS log provides no extra details.
Folder permissions or having Excel closed or open when running the code as per this question's answer, or using an empty dataset, makes no difference. The SAS website mentions that this error can occur when using PROC EXPORT with DBMS=CSV, and it can be avoided by using name-literal syntax. However, using it as per below makes no difference.
proc export data = work.'dataset'n
outfile = "C:\MBorg\dataset.csv"
dbms = csv replace;
run;
Strangely the only way I can find to circumvent the problem is resetting SAS. options obs=max makes no difference. Not sure what causes this message. This occurred with SAS 9.4 M0 and M7.
Any help with exporting CSV files without resetting SAS would be helpful.
Try writing your own step(s) to write the text file instead of asking PROC EXPORT to generate one for you. That should at least make the error message clearer.
* Get list of variables names ;
proc transpose data=DATASET(obs=0) out=_names_; var _all_; run;
* Write header row ;
data _null_;
file "C:\MBorg\dataset.csv" dsd lrecl=2000000 ;
set _names_;
put _name_ # ;
run;
* Write data rows ;
data _null_;
file "C:\MBorg\dataset.csv" dsd lrecl=2000000 mod;
set DATASET;
put (_all_) (+0) ;
run;
I have been trying to import a large Excel file in SAS consisting 20 worksheets. I am using following macro for proc import
%macro excel_imp(outds, worksheet);
proc import
out=&outds
datafile= "Z:\temp\sample"
dbms=XLSX replace;
sheet="&worksheet";
getnames=yes;
run;
%mend excel_imp;
%excel_imp(Ds1,Worksheet1);
%excel_imp(Ds2,Worksheet2);
The above code is running fine, but I have to call the macro 20 times with separate worksheet names.
I would like an automated code to identify the worksheet names and then use the macro above. I don't have pcfiles/ExcelCS in my SAS EG, I am using 9.4
Appreciate any help! Thanks.
Since XLSX clearly works, why not use the XLSX libname.
libname demo xlsx 'path to xlsx file';
proc copy in=demo out=work;
run;
I have a table in sas format (.sas7bdat) and would like to output it in Jupyter notebook.
proc print data=dataBoxE.my_data (firstobs=2 obs=12);
run;
The output table is jammed together since it has 100+ columns. How should I setup the environment within my notebook?
Moreover, is there a way to save the log file instead of opening it right away in the output cell? Thanks.
In SAS you can change the location of where the log file is created using proc printto; Documentation here.
When using proc printto, don't forget to reset the location to the default system value at the end of your, Example:
proc printto log='c:\em\log1.log';
run;
/* Your code here */
proc printto;
run;
If you don't need the 100+ columns; then select only the ones you want using the VAR statement in proc print Documentation here :
proc print data=exprev;
var country price sale_type;
run;
If you want all the 100+; just export them to csv using proc export and view them in any spreadsheet reader to avoid crashing your browser. Documentation here.
proc export data=sashelp.class
outfile='c:\myfiles\Femalelist.csv'
dbms=csv
replace;
run;
I was doing a PCA analysis with SAS using the following code:
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
Because the lst files this analysis produces is too large, I used the NOPRINT option. However, it seems that the NOPRINT option also eliminates all of my ODS outputs. (Now PRINCEEV and PRINCEEVAL are all empty):
ERROR: File WORK.PRINCEEVAL.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
259 putn
_______
1
259 ! ame=YES; run;
WARNING 1-322: Assuming the symbol PUTNAMES was misspelled as putname.
ERROR: File WORK.PRINCEEV.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
ERROR: Errors printed on page 1.
Is there a way to suppress the generation of lst file, without affecting the ods output?
UPDATE:
It seems that according to the following sas blog, it is not possible to do that:
Can you combine NOPRINT and ODS OUTPUT?
SAS programmers crave efficiency. Upon reading that the NOPRINT option
can make a procedure run faster, the ambitious programmer might
attempt to run a procedure with the NOPRINT option but use the ODS
OUTPUT statement to capture the results of one table. Sorry, friend,
but you can't do that. The NOPRINT option means that no ODS tables are
created, so there is no way to select a table and save it to a data
set.
But the dilemma is, I have limited space on the cloud computing server. The lst files are doing nothing but wasting my spaces. Deleting the lst files when SAS programs are running with external processes will also produce an io error in SAS (I already tried that).
Is there anyway around?
I would suggest:
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
This will close the listing destination, so should work fine.
I noticed in a related blog post, Rick argued for:
ods exclude _all_ ;
http://blogs.sas.com/content/iml/2015/05/28/five-reasons-ods-exclude.html
Minor change to the previous answer: remove the NOPRINT option and after the ODS OUTPUT is created open up the ods listing if you have further code.
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) /*NOPRINT*/;
id time;
run;
ods output close;
ODS LISTING;
If you execute your sas-script on your cloud computing server via bash, then you can send your .lst files to /dev/null:
sas -print /dev/null script.sas
The -print option only effects your .lst, but not any ODS related outputs.
I am using SAS Enterprise Guide, importing American Community Survey tables from the census into a script to work with them. Here is an example of a raw census csv I'm importing into SAS Enterprise Guide:
within my data step, when I use the command
County=Geo.display-label;
I get this error:
In base SAS, I was using
County=Geo_display_label;
While that worked in base SAS, when I tried that in Enterprise Guide, I got this error:
What is a way to get the raw data's variable name Geo.display-label to read into SAS Enterprise Guide correctly?
To see the impact of the VALIDVARNAME option on the names that PROC IMPORT generates when the column headers are not valid SAS names lets make a little test CSV file.
filename csv temp ;
data _null_;
file csv ;
put 'GEO.id,GEO.id2,GEO.display-label';
put 'id1,id2,geography';
run;
If we run PROC IMPORT to convert that into a SAS datasets when VALIDVARNAME option is set to ANY then it will use the column headers exactly, including the illegal characters like period and hyphen. To reference the variables with those illegal characters we will need to use name literals.
options validvarname=any;
proc import datafile=csv replace out=test1 dbms=dlm;
delimiter=',';
run;
proc contents data=test1; run;
proc freq data=test1;
tables 'GEO.display-label'n ;
run;
But if we set the option to V7 instead then it will convert the illegal characters into underscores.
options validvarname=v7;
proc import datafile=csv replace out=test2 dbms=dlm;
delimiter=',';
run;
proc contents data=test2; run;
proc freq data=test2;
tables geo_display_label ;
run;
County = 'geo.display-label'n;
if you set OPTIONS VALIDVARNAME=V7; in EG you will get the same names as batch sas.