Export from SAS to Excel in month name sheets - sas

Can you, please, help me to find a solution for my export from SAS to Excel.
Here it's my export procedure:
%let today=%sysfunc(today());
%let date1= %sysfunc(intnx(month,&today,-1,B));
%let expectdate1=%sysfunc(putn(%eval(&date1),monname8.));
proc export
data=WORK.table
DBMS=XLSX
outfile="C:\FILE.xlsx"
REPLACE;
SHEET="&expectdate1";
run;**
The export creates me, as expected, a worksheet named "August" into FILE.xlsx.
My problem is when I'm inserting another workheet before the just created one (August). If I manually create a July worksheet before August, then my export procedure doesn't replace data from August, but it's gonna add the new information into July worksheet.
Thank you in advance for your solution.
Regards,
Dan

The probleme is solved. I've changed DBMS=XLSX with DBMS=EXCEL and I've got what I was expecting: information is added in worksheet named by expectdate1 variable, no metter what is the worksheet position.

Related

After using proc import on an excel file, how am i able to use that data?

I've imported the excel file and it says the data file work.one has been created, but how am i able to manipulate this file?
What im trying to do is transform PSA to ln(PSA+1) in most analyses using PSA, where PSA is the excel file I imported. I am using base SAS.
This is my code so far
data excl;
proc import out = psa
datafile= "H:\MinitabFiles\Morrell\SAS-Data\psa.xls"
dbms = xls replace;
sheet = "psa";
getnames = yes;
run;
data logs;
set excl;
sheet = log(sheet+1);
run;'
What do you want to do with it?
You'll find it in the work library under the explorer tree assuming you are using Enterprise Guide. To 'manipulate' it, many of your most obvious options will be covered by proc sql; or a datastep.
Please elaborate on the question if you want a more useful answer:-
1 which sas product are you using? EG, Base, etc?
2 have you located the file and established it has been imported correctly?
3 `manipulate'? What does this mean? Filter, perform calculations, functions, conversions or one of many other things.
Welcome btw, but please provide plenty more detail.
You have issues with your current code. For example the data excl doesn't do anything. PROC IMPORT creates the data, the data step around the PROC IMPORT is useless.
data excl; *REMOVE THIS, DOES NOT DO ANYTHING;
proc import out = psa /*PSA is the name of the output data set*/
datafile= "H:\MinitabFiles\Morrell\SAS-Data\psa.xls"
dbms = xls replace;
sheet = "psa";
getnames = yes;
run; *THIS GOES WITH THE PROC IMPORT;
data logs;
set excl; *YOUR DATASET IS CALLED PSA, replace EXCL with PSA;
sheet = log(sheet+1); *This assumes your PSA data set has a variable with sheet;
run;'

SAS import single cell value from Excel spreadsheet

I am using sas 9.2 and i want top import a cell value from a spreadsheet
the value i want are F4 located in the sheet "data beskrivelse"
This i what i do:
proc import out=TESTER
datafile="&request_in"
dbms=XLS replace;
RANGE="data beskrivelse$F4:F5";
run;
And it works ok, but the result is that the column name gets the value in F4 and
the data from F5 is imported.
So my sas dataset has ha column where the header name are the value of F4.
if i change the range in proc import to
proc import out=TESTER
datafile="&request_in"
dbms=XLS replace;
RANGE="data beskrivelse$F4:F4";
run;
I'll get the whole column imported from the spreadsheet.
So basically i want the value from F4 to be imported into my sas dataset in variable A
Oh i managed to figure it out,
the solution is to use the getnames option in proc imort
it says wether to import as names or not.
so i changed to this
proc import out=TESTER
datafile="&request_in"
dbms=XLS replace;
getnames=NO;
RANGE="data beskrivelse$F4:F4";
run;
and i get the value in as data in my dataset.

Define Library in SAS where some of the Folder name will be change each time(When this SAS macro run from different users)

Topic: SAS Library
Difficulty: path(File name and Location) is changing after each run but only some of the details are changing but not the full path (as given in below example). we have also highlighted those field in Bold
I want to write only one code where I can cover all kind of change which happening in file name and location, is it possible?
%let path='C:\Data\variationstring\empcat**A**\person**34**_**1212**\persondata_empcatA_**34**';
libname test "&path";
proc import datafile="&path\Accounts_**34**.xls"
out=mydata
sheet="thefile";
getnames=no;
run;
When another user run that program then above path will be changed:
%let path='C:\Data\variationstring\empcat**A**\person**49**_**1684**\persondata_empcatA_**49**';
libname test "&path";
proc import datafile="&path\Accouns_**49**.xls"
out=mydata
sheet="thefile";
getnames=no;
run;
Can anyone help me for this, please?
Thanks
Try to put it in a macro like this:
%macro import (macro_var1,macro_var2,macro_var3);
%let path="C:\Data\variationstring\empcat**A**\person**&macro_var1.**_**&macro_var2.**\persondata_empcatA_**&macro_var3.**";
libname test "&path";
proc import datafile="&path\Accouns_**49**.xls"
out=mydata
sheet="thefile";
getnames=no;
run;
%mend;
%import (34, 1212, 34);
%imoprt (49, 1684, 49);
etc.
when defining path, don't forget to put it in double quotes (") insted of single (')
In addition to Grigory's excellent suggestion, it looks to me like you're doing something that would be well served utilizing a data-driven programming approach.
If you have, say, an excel spreadsheet with all of your personnel records - let's say the first number is store and the second is employeeID - and you want to run one report per employeeID, then you write the macro like Grigory suggested; but you call the report from the first dataset.
So here:
proc import file="C:\Data\employeeID.xlsx"
out=employees dbms=xlsx
replace;
run;
%macro get_employee(store=, employeeID=, empCat=);
%let path="C:\Data\variationstring\empcat&empcat.\person&store._&employeeID.\persondata_empcat&empcat._&store.";
libname test "&path";
proc import datafile="&path\Accouns_&store..xls"
out=mydata
sheet="thefile";
getnames=no;
run;
%mend get_employee;
proc sql; *this generates macro calls, look at output to see what the macro variable contains;
select cats('%get_employee(employeeid=',employeeID,',store=',store,',empcat=',empcat,')')
into :get_emp_list separated by ' '
from employees;
quit;
&get_emp_list.; *This actually runs all those macro calls;
You can read my paper, Writing Code With Your Data for more details, or find other similar papers online.

How to obtain the date of a most recently created dataset in SAS libname

I am trying to write some code that will look at all the datasets in a libname and bring back the created date of the most recently created file.
I have googled this for an entire day and cannot find a way to do this. I know that ATTRN can determine the created date of a dataset:
%let data_set = libname.data_set_name;
%let dsid = %sysfunc (open(&data_set));
%let create_date = %sysfunc(attrn(&dsid, crdte));
But there seems to be no way to make it look at multiple datasets so that a max date can be determined.
Can anyone please help?
OK, so I eventually found this bit of code in "Get Control of Your Input: Refer to Multiple Data Files Efficiently" a paper by Zhongping Zhai, Bloomington, IL and this works nicely for me:
proc sql;
create table all_datasets as
select memname, crdate
from dictionary.tables
where libname="LIBNAME" and memname like "DSN%";
quit;
Hope this helps someone else too!

Incorporate the date into filename

I have a report need to send other sharedrive, need to send title and the date. How can I do that
PROC EXPORT DATA= WORK.ARG_REPORT
OUTFILE= "/dwdata/sas_data/REPORT.csv" REPLACE;
RUN;
what can i add to REPORT for see the date? thaks
You need to create a macro variable with the date especially if the date will change depending on when you run the code. Then reference that variable in the export statement.
The code below grabs today's date.
%let numdate = %sysfunc(today(), yymmddn8.);
PROC EXPORT DATA= WORK.ARG_REPORT
OUTFILE= "/dwdata/sas_data/REPORT_&numdate..csv"
DBMS=CSV REPLACE;
RUN;