Desktop productivity for business analysts and programmers

transferring files

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 318
Accepted Solution

transferring files

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;


Accepted Solutions
Solution
‎04-10-2014 01:45 PM
Grand Advisor
Posts: 17,338

Re: transferring files

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


All Replies
Trusted Advisor
Posts: 1,056

Re: transferring files

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

Super Contributor
Super Contributor
Posts: 318

Re: transferring files

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;

Super Contributor
Posts: 1,636

Re: transferring files

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";

Super Contributor
Super Contributor
Posts: 318

Re: transferring files

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!

Solution
‎04-10-2014 01:45 PM
Grand Advisor
Posts: 17,338

Re: transferring files

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;

Super Contributor
Super Contributor
Posts: 318

Re: transferring files

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

Worked fine...

Thanks all!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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