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

Hello friends,

i am using below code to transfer some files (mdb) from one folder to couple of different share folders...and code is completely working fine...

now i need to add one more path (red color) which is quite different and i am not sure how i can include that in copycmd statement (highlighted with bold blue color)...

can someone please help...?

/*Background/*

/*i have one control table as below*/

work.control

Username    Location

USUser1     NY

USUser2     PA

USUser3     NY

USUser4     PA

USUser5     NJ

USUser6     NJ

/*I have some mdb files @ below locaiton.*/

f:\woo\db\

USUser1_market.mdb

USUser2_market.mdb

USUser3_market.mdb

USUser4_market.mdb

Code

-----------------------------------------

/*all above mdb files should goes to proper location either to NY folder or PA folder or NJ folder (New one)  - see path below*/

proc format;

value $ location

                      "NY"="f:\transfer\mdb\ny"

                      "PA"="f:\mkt\files\pa";

                      "NJ"="f:\shares\market database\design & dev\business applications\finance - planning\nj"

run;

%let path=f:\woo\db ;

data files ;

   infile "dir /b &path\*.mdb" pipe truncover lrecl=256 ;

   input filename $256. ;

   username = scan(filename,1,'_');

run;

data both ;

  merge files (in=in1) control (in=in2);

  by username ;

  if in1 ;

  targetdir = put(location,$location.);

run;

data both ;

  merge files (in=in1) control (in=in2);

  by username ;

  if in1 ;

  targetdir = put(location,$location.);

  copycmd = catx(' ','copy'

                 ,quote(cats("&path\", filename))

                  ,quote(cats(targetdir))

             );

run;

data _null_;

    set both ;

    infile cmd pipe filevar=copycmd ;

    *input @;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Add a length statement for the variable copycmd to make it longer than 256 characters...at least that seems to be what the warning messages says to me.

data both ;

     length copycmd $512.;

  merge files (in=in1) control (in=in2);

  by username ;

  if in1 ;

  targetdir = put(location,$location.);

  copycmd = catx(' ','copy'

                 ,quote(cats("&path\", filename))

                  ,quote(cats(targetdir))

             );

run;

View solution in original post

6 REPLIES 6
TomKari
Onyx | Level 15

It's not looking bad;

Problem one: move the semicolon from the end of "PA"="f:\mkt\files\pa" to the end of "NJ"="f:\shares\market database\design & dev\business applications\finance - planning\nj".

Question two: Why the two "data both" steps? The second one alone should be sufficient.

Problem three: I think your last "data _null_" should have file instead of infile, and put instead of input, but I can't test that.

Of course, you need "USUser5_market.mdb" and "USUser6_market.mdb" in your input directory.

Your approach is quite sound; it's very close to working.

Tom

woo
Barite | Level 11 woo
Barite | Level 11

Tom - below code is working fine except for "NJ" path. i am getting "copycmd" var exactly like mentioned below but not getting anything for NJ path in second "data both" step...

--------------------------------------------------------------------------------------------------------------------------

/*i am not getting value for NJ path for this variable*/

copycmd

copy "f:\woo\db\USUser1_market.mdb" "f:\transfer\mdb\ny\USUser1_market.mdb"

copy "f:\woo\db\USUser2_market.mdb" "f:\mkt\files\pa\USUser2_market.mdb"

copy "f:\woo\db\USUser3_market.mdb" "f:\transfer\mdb\ny\USUser3_market.mdb

copy "f:\woo\db\USUser4_market.mdb" "f:\mkt\files\pa\USUser2_market.mdb"

------------------------------------------------------------------------------------------------------------------------

/*i have different path name for my original code but path contains same space, & and - (hyphen) signs for NJ path*/

getting this warning message:

WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough

         to contain the concatenation of all the arguments. The correct result would contain 203

         characters, but the actual result may either be truncated to 200 character(s) or be

         completely blank, depending on the calling environment. The following note indicates the

         left-most argument that caused truncation.

---------------------------------------------------------

proc format;

value $ location

                      "NY"="f:\transfer\mdb\ny"

                      "PA"="f:\mkt\files\pa"

                      "NJ"="f:\shares\market database\design & dev\business applications\finance - planning\nj";

run;

%let path=f:\woo\db ;

data files ;

   infile "dir /b &path\*.mdb" pipe truncover lrecl=256 ;

   input filename $256. ;

   username = scan(filename,1,'_');

run;

data both ;

  merge files (in=in1) control (in=in2);

  by username ;

  if in1 ;

  targetdir = put(location,$location.);

run;

data both ;

  merge files (in=in1) control (in=in2);

  by username ;

  if in1 ;

  targetdir = put(location,$location.);

  copycmd = catx(' ','copy'

                 ,quote(cats("&path\", filename))

                  ,quote(cats(targetdir))

             );

run;

data _null_;

    set both ;

    infile cmd pipe filevar=copycmd ;

    input @;

run;

Linlin
Lapis Lazuli | Level 10

Hi,

trying change

"NJ"="f:\shares\market database\design & dev\business applications\finance - planning\nj";

to

"NJ"="f:\shares\"market database"\"design & dev"\"business applications"\"finance - planning"\nj";

woo
Barite | Level 11 woo
Barite | Level 11

nop, still having same warning message... i am assuming something needs to be changed in "copycmd" statement because i am having everything right until that last "DATA BOTH" step...

Thanks!

Reeza
Super User

Add a length statement for the variable copycmd to make it longer than 256 characters...at least that seems to be what the warning messages says to me.

data both ;

     length copycmd $512.;

  merge files (in=in1) control (in=in2);

  by username ;

  if in1 ;

  targetdir = put(location,$location.);

  copycmd = catx(' ','copy'

                 ,quote(cats("&path\", filename))

                  ,quote(cats(targetdir))

             );

run;

woo
Barite | Level 11 woo
Barite | Level 11

Anyways it's Reeza's solution...Smiley Happy

Worked fine...

Thanks all!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1578 views
  • 0 likes
  • 4 in conversation