BookmarkSubscribeRSS Feed
RDS2020
Calcite | Level 5

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

5 REPLIES 5
Tom
Super User Tom
Super User

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.  

Shmuel
Garnet | Level 18

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.

RDS2020
Calcite | Level 5

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.);

 

Kurt_Bremser
Super User

A UNIX system will regard a double slash as "missing", and make one slash out of the two.

The bigger issues I see:

  • blanks in directory and file names. This is (in about 100% of cases) a BAD IDEA and makes subsequent use harder, for no recognizable gain. Use underlines as a "word separator".
  • 2-digit years. Really? Ever heard of "Y2K Scare"? Only when reading your code I found out that "2008" is not the year 2008, but August 2020.
  • redundant information in a single name. "2008" and Aug2020 mean the same.
  • use of names for months. They do not sort in any usable way.
  • use of the DMY order in file date stamps. Use YMD instead, makes life much easier.

Your path will be much easier to handle in the future in this form:

/xyz/Stats/2020_08/abc_2020_08_09.xlsx

 

Tom
Super User Tom
Super User

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1030 views
  • 1 like
  • 4 in conversation