Why does this return spaces/tab between 2 variables(JAN 2006)?
I have pasted my code below.
I am trying to automate the date in the filename. The problem here is is that it's used multiple times in the query and it's usually run backwards in time on a monthly basis.
So I have setup a simple macro variable that filters on the dates, but the filename isn't as easily updated. Any tips or suggestions?
If it wasn't on a monthly basis I would have simply used %sysdate function.
PROC SQL;
CREATE TABLE TEST AS
SELECT * FROM SASHELP.RENT
;
RUN;
PROC SQL;
SELECT TRIM(YEAR(MAX(date)))
INTO :year
FROM test;
RUn;
PROC SQL;
SELECT
CASE
WHEN MONTH(MAX(DATE))=1
THEN "JAN"
WHEN MONTH(MAX(DATE))=2
THEN "FEB"
WHEN MONTH(MAX(DATE))=3
THEN "MAR"
WHEN MONTH(MAX(DATE))=4
THEN "APR"
WHEN MONTH(MAX(DATE))=5
THEN "MEI"
WHEN MONTH(MAX(DATE))=6
THEN "JUN"
WHEN MONTH(MAX(DATE))=7
THEN "JUL"
WHEN MONTH(MAX(DATE))=8
THEN "AUG"
WHEN MONTH(MAX(DATE))=9
THEN "SEP"
WHEN MONTH(MAX(DATE))=10
THEN "OKT"
WHEN MONTH(MAX(DATE))=11
THEN "NOV"
WHEN MONTH(MAX(DATE))=12
THEN "DEC"
END AS maand
INTO :maand
FROM test;
RUn;
PROC EXPORT
DATA=test
outfile = "\\test-&maand&year"
dbms =xlsx replace;
RUN;
Here is how I would simplify it.
proc sql noprint;
select year(date)
, put(month(date), monname3.)
into :year separated by ''
, :month separated by ''
from sashelp.rent
having max(date) = date;
run;
%put &year.;
%put &month.;
%put \\test-&month.&year.;