In EG I want to create a report and export it using a macro variable in the name of the export file, so that if I re-run the report and the variable changes (i.e. a timestamp) it will not override my previous report.
When I create a report using proc report is automatically names my report after the code that created it. The export function is created in a point and click function and I can't use macro variables in there. Is there a simple way to name a report in the proc report procedure?
process flow screen shot
Yes you can
You will have to use proc export or do a datastep using infile
here is an example with proc export
proc sql outobs=1;
select datetime :into dt
from table;
proc export data=<report_data>
OUTFILE="<path_to_file>/report_&dt..csv"
DBMS=CSV LABEL REPLACE;
RUN;
that should work well!
Related
I have imported a dataset from a an excel sheet, and I want to delete some observations. Say, I have a variable which tells me if a student has passed or not (with strings "Passed" and "Failed"). I want to delete all the students which have failed from the dataset.
I do know that usually I would be able to do so with an if statement. However, I don't know how to access the temporary dataset. Do I have to open after importing it, and then check with an if statement?
This is how I have tried:
proc import datafile="C:\Users\User\Desktop\testresults.xlsx"
DBMS=XLSX;
if Status = "failed" then delete
run;
I know this won't work as the "if" condition only works when the data resides in PDV.
Is it possible to delete after importing instead of while importing?
Use a where clause on the output data set:
proc import file="my.xlsx"
out=work.myxlsx(where=(status^="failed"))
dbms=xlsx
replace;
run;
A where statement would modify the output dataset from PROC IMPORT, as DomPazz shows.
Alternately, you can use a data step.
proc import datafile="C:\Users\User\Desktop\testresults.xlsx" out=have DBMS=XLSX;
run;
data want;
set have;
if Status = "failed" then delete;
run;
That of course would work whether you did it immediately after importing (or in the same submit) or some time later.
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 have SAS guide output.
I want to PROC export him, the problem is that when i export him to excel
All the format changes.
When I use in the SAS guide the "export as step in the..." everything is ok.
But I need the PROC export
So , how can I export and save all of the format ?
Thanks
PROC EXPORT DATA= WORK.data
OUTFILE= "c:\your_path\OutputFileName"
DBMS=XLS LABEL REPLACE;
NEWFILE=YES;
RUN;
For more on proc export see http://support.sas.com/documentation/cdl/en/proc/70377/HTML/default/viewer.htm#n045uxf7ll2p5on1ly4at3vpd47e.htm
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.
If using the proc report procedure in SAS, how to stop the proc report procedure?
I try to use "RUN" statement or "quit" statement, but these statements cannot solve the problem.
You need the NOWD (NoWindow) option on your proc report statement.
Its leftover from when people used the interactive report builder interface.
Proc report data = have nowd;