BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vicky07
Quartz | Level 8

Hi,

In the below code I am using a macro to create a folder if doesn't exist and use the same folder to assign a libname. When i run the code  for the first time the folder create step works fine but the libname is not getting assigned.

However, if i run the same code again in the same session the libname is getting successfully assigned.

Options noxwait;

%Let monyyyy = %sysfunc(putn(%sysfunc(today()),monyy7.));

%Macro chk;

Data _null_;

if not fileexist("C:\Reports\&monyyyy.\&sysdate.") then rc=system("mkdir "C:\Reports\&monyyyy.\&sysdate.");

Run;

%Let fpath = C:\Reports\&monyyyy.\&sysdate.;

libname rep "&fpath.";

%Mend;

%Chk;

Does anybody have any idea, why is this happening.? Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I would try removing the unneeded periods after &sysdate and &fpath. The example code then works on my system.

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

I dont think you need a macro at all. But the error could be caused by missing quotes in your system function call.

PG

PG
vicky07
Quartz | Level 8

PG,

Thanks for the reply. I didn't list the entire code  here and i have some steps after the libname which requires Macro. Actually, there was no quotes in my original code I typed it incorrectly in the forum, good catch though. I removed the quotes in the below code. Please let me know if you think something else could be causing the error.

%Let monyyyy = %sysfunc(putn(%sysfunc(today()),monyy7.));

%Macro chk;

Data _null_;

if not fileexist("C:\Reports\&monyyyy.\&sysdate.") then rc=system("mkdir C:\Reports\&monyyyy.\&sysdate.");

Run;

%Let fpath = C:\Reports\&monyyyy.\&sysdate.;

libname rep "&fpath.";

%Mend;

%Chk;

ballardw
Super User

I would try removing the unneeded periods after &sysdate and &fpath. The example code then works on my system.

vicky07
Quartz | Level 8

Removing the periods worked. Thank you very much!!!

Tom
Super User Tom
Super User

The trailing periods looked fine before, perhaps you removed some spaces when you removed the periods?  Using proportional fonts can make that type of thing very hard to see.

It would be easier and less error prone to assign the FPATH macro variable and then use it.  Then you have the logic for building the path in one place instead of three.

You also might want to quote the path when passing it to the mkdir command. Many DOS commands require quotes to handle paths with embedded spaces correctly.

%Let monyyyy = %sysfunc(putn(%sysfunc(today()),monyy7.));

%macro chk;

%Let fpath = C:\Reports\&monyyyy\&sysdate;

data _null_;

  if not fileexist("&fpath") then rc=system("mkdir ""&fpath""");

run;

libname rep "&fpath";

%mend chk;


%chk;

vicky07
Quartz | Level 8

Tom,

Your solution make sense and it worked. Thanks for the reply!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 6 replies
  • 17679 views
  • 5 likes
  • 4 in conversation