Hi All,
Sometimes when i run SAS program to give path of the file it adds 1 additional to the path thus my program files.
What i run:-
%LET YEAR = %SYSFUNC(TODAY(),YEAR4.);
%PUT &YEAR.;
%LET YY = %SYSFUNC(TODAY(), YEAR2.);
%PUT &YY.;
%LET MONTH_N = %sysfunc(month("&sysdate"d),z2.);
%PUT &MONTH_N.;
%LET MONTH_C = %SYSFUNC(TODAY(), MONNAME3.);
%PUT &MONTH_C.;
%LET DATE = %SYSFUNC(TODAY(), DAY2.);
%PUT &DATE.;
%LET PATH = /xyz/Stats;
PROC IMPORT
DATAFILE = "&path./&YY.&MONTH_N. - &MONTH_C. &YEAR./abc &DATE.&MONTH_C. &YEAR..xlsx"
DBMS = XLSX
OUT = raw_data
REPLACE;
GETNAMES = YES;
RUN;
and When i run it i get this:-
ERROR: Physical file does not exist,
/xyz/Stats/2008 - Aug 2020//abc 9Aug 2020.xlsx.
So if you see there are 2 "/" before abc eve though in program i write one 1 "/" and this happens quite often. What is the reason and how to resolve it .
Thanks
RDS
Show more of the SAS log to see what is generating that error message. It might just be that whatever step that is generating the error message is adding the extra slash into the error message and the value you generated was fine but non existant.
I have run your code excluding the proc import, and there is no double "/".
Please post the full log as mine here:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 %LET YEAR = %SYSFUNC(TODAY(),YEAR4.); 74 %PUT YEAR = &YEAR.; YEAR = 2020 75 %LET YY = %SYSFUNC(TODAY(), YEAR2.); 76 %PUT YY = &YY.; YY = 20 77 %LET MONTH_N = %sysfunc(month("&sysdate"d),z2.); 78 %PUT MONTH_N = &MONTH_N.; MONTH_N = 08 79 %LET MONTH_C = %SYSFUNC(TODAY(), MONNAME3.); 80 %PUT MONTH_C = &MONTH_C.; MONTH_C = Aug 81 %LET DATE = %SYSFUNC(TODAY(), DAY2.); 82 %PUT DATE= &DATE.; DATE= 9 83 %LET PATH = /xyz/Stats; 84 %let DATAFILE = "&path./&YY.&MONTH_N. - &MONTH_C. &YEAR./abc &DATE.&MONTH_C. &YEAR..xlsx"; 85 %put datafile = &datafile; datafile = "/xyz/Stats/2008 - Aug 2020/abc 9Aug 2020.xlsx" 86
Check your code again.
Hi All,
Thanks for replying. I figured out the problem, the filename is coming out to be bit different. Error is showing for below
ERROR: Physical file does not exist,
/xyz/Stats/2008 - Aug 2020//abc 9Aug 2020.xlsx.
where as filename is abc 09Aug 2020.xlsx.
so this step giving me 9Aug and filename is 09Aug. Anyway i can make 9Aug as 09Aug while performing below line of code.
%LET DATE = %SYSFUNC(TODAY(), DAY2.);
A UNIX system will regard a double slash as "missing", and make one slash out of the two.
The bigger issues I see:
Your path will be much easier to handle in the future in this form:
/xyz/Stats/2020_08/abc_2020_08_09.xlsx
Better to call the DATE() function (aka TODAY() function) just once to avoid confusion if your program happens to start right before midnight. You can use that date value with the DATE9 and YYMMN4 formats to get the strings you need: 2 digit day, 2 digit month, 2 digit year, 4 digit year and three character month. If you really need the month letters in propcase instead of upcase then you could use the MONNAME3. format instead of pulling the month from the output of the DATE9 format.
%let today=%sysfunc(today());
%let yymm = %sysfunc(putn(&today,yymmn4.));
%let date = %sysfunc(putn(&today,date9.));
%let month = %sysfunc(putn(&today,monname3.));
%let day = %substr(&date,1,2);
%let year = %substr(&date,6);
936 %put &=path &=yymm &=month &=year &=day ; PATH=/xyz/Stats YYMM=2008 MONTH=Aug YEAR=2020 DAY=09 937 938 %put "&path./&yymm. - &month. &year./abc &day.&month. &year..xlsx" ; "/xyz/Stats/2008 - Aug 2020/abc 09Aug 2020.xlsx"
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.