Rename File with SAS

  • Follow


hello sas-users,

I have a folder which contains several file like : "A_X1.csv",
"A_X2.csv", "A_X3.csv" ... (I will not know how many file I have in
the folder).

How can I do a SAS program to rename each file and obtain :
"CC_X1.csv", "CC_X2.csv", "CC_X3.csv" ... (replace the A by CC).

Thanks.

ash_rmy
0
Reply ash007 8/16/2010 2:41:42 PM

On Aug 16, 10:41=A0am, ash007 <ramsamyash...@gmail.com> wrote:
> hello sas-users,
>
> I have a folder which contains several file like : "A_X1.csv",
> "A_X2.csv", "A_X3.csv" ... (I will not know how many file I have in
> the folder).
>
> How can I do a SAS program to rename each file and obtain :
> "CC_X1.csv", "CC_X2.csv", "CC_X3.csv" ... (replace the A by CC).

You probably are going to need to write a macro to do this. And for us
to help, we would need to know what operating system you are using.

--
Paige Miller
paige\dot\miller \at\ kodak\dot\com

0
Reply Paige 8/16/2010 3:57:45 PM


Hello.

I m working with SAS Windows.

Thanks.

ash_rmy.
0
Reply Vishwanath 8/16/2010 7:00:33 PM

Hello.

I m working with SAS Windows.

Thanks.

ash_rmy.
0
Reply ash007 8/16/2010 7:02:05 PM

I ve done this program. :)


%MACRO TRAITEMENT_RENOMMAGE
(
	__CHEMIN =3D, /*chemin o=F9 sont stock=E9s les fichiers =E0 renommer*/
	__CHAINE_A_SUPP =3D /*cha=EEne de caract=E8res =E0 supprimer*/
);

OPTIONS SYMBOLGEN MACROGEN MPRINT MLOGIC NOXWAIT;

DATA _NULL_;
	FICHIERPIPE =3D CAT("DIR ","&__CHEMIN.","*.CSV /B");
	CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
RUN; %PUT &__FICHIERPIPE.;

FILENAME FICH_CSV PIPE "&__FICHIERPIPE.";

DATA LISTECSV;
    LENGTH NOMCSV $500; INFILE FICH_CSV TRUNCOVER;
    INPUT NOMCSV $500.;
	CHEMIN =3D "&__CHEMIN.";
RUN;

DATA _NULL_;
	SET LISTECSV;
	CALL SYMPUT(COMPRESS("CHEM_FIC_CSV"||_N_),COMPRESS(CHEMIN||NOMCSV));
RUN; %PUT &CHEM_FIC_CSV1.;

DATA LISTECSV;
	SET LISTECSV;
	NEW_NAME =3D COMPRESS(SUBSTR(NOMCSV,
%SYSFUNC(LENGTH(COMPRESS(&__CHAINE_A_SUPP.)))+1,LENGTH(NOMCSV)-
%SYSFUNC(LENGTH(COMPRESS(&__CHAINE_A_SUPP.)))));
CALL SYMPUT(COMPRESS("NEW_NAME_CSV"||_N_),COMPRESS(NEW_NAME));
RUN; %PUT &NEW_NAME_CSV1.;

DATA _NULL_;
	SET LISTECSV END =3D FIN;
	IF FIN THEN CALL SYMPUT("__NOMBREOBS",TRIM(LEFT(PUT(_N_,BEST8.))));
RUN; %PUT &__NOMBREOBS.;

%DO I =3D 1 %TO &__NOMBREOBS.;
		%SYSEXEC(RENAME &&CHEM_FIC_CSV&I. &&NEW_NAME_CSV&I.);
	%END;

%MEND TRAITEMENT_RENOMMAGE;

%TRAITEMENT_RENOMMAGE
(
	__CHEMIN =3D C:\USERS\SUADEO\ASHLEY\TMP\,
	__CHAINE_A_SUPP =3D NOM_CLASSEUR_
);
0
Reply ramsamyashley (267) 8/17/2010 10:05:22 AM

I ve done this program. :)


%MACRO TRAITEMENT_RENOMMAGE
(
	__CHEMIN =3D, /*chemin o=F9 sont stock=E9s les fichiers =E0 renommer*/
	__CHAINE_A_SUPP =3D /*cha=EEne de caract=E8res =E0 supprimer*/
);

OPTIONS SYMBOLGEN MACROGEN MPRINT MLOGIC NOXWAIT;

DATA _NULL_;
	FICHIERPIPE =3D CAT("DIR ","&__CHEMIN.","*.CSV /B");
	CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
RUN; %PUT &__FICHIERPIPE.;

FILENAME FICH_CSV PIPE "&__FICHIERPIPE.";

DATA LISTECSV;
    LENGTH NOMCSV $500; INFILE FICH_CSV TRUNCOVER;
    INPUT NOMCSV $500.;
	CHEMIN =3D "&__CHEMIN.";
RUN;

DATA _NULL_;
	SET LISTECSV;
	CALL SYMPUT(COMPRESS("CHEM_FIC_CSV"||_N_),COMPRESS(CHEMIN||NOMCSV));
RUN; %PUT &CHEM_FIC_CSV1.;

DATA LISTECSV;
	SET LISTECSV;
	NEW_NAME =3D COMPRESS(SUBSTR(NOMCSV,
%SYSFUNC(LENGTH(COMPRESS(&__CHAINE_A_SUPP.)))+1,LENGTH(NOMCSV)-
%SYSFUNC(LENGTH(COMPRESS(&__CHAINE_A_SUPP.)))));
CALL SYMPUT(COMPRESS("NEW_NAME_CSV"||_N_),COMPRESS(NEW_NAME));
RUN; %PUT &NEW_NAME_CSV1.;

DATA _NULL_;
	SET LISTECSV END =3D FIN;
	IF FIN THEN CALL SYMPUT("__NOMBREOBS",TRIM(LEFT(PUT(_N_,BEST8.))));
RUN; %PUT &__NOMBREOBS.;

%DO I =3D 1 %TO &__NOMBREOBS.;
		%SYSEXEC(RENAME &&CHEM_FIC_CSV&I. &&NEW_NAME_CSV&I.);
	%END;

%MEND TRAITEMENT_RENOMMAGE;

%TRAITEMENT_RENOMMAGE
(
	__CHEMIN =3D C:\USERS\SUADEO\ASHLEY\TMP\,
	__CHAINE_A_SUPP =3D NOM_CLASSEUR_
);
0
Reply ramsamyashley (267) 8/17/2010 10:05:27 AM

You will not need (or WANT) a macro to do this.  Read the names into a
dataset and generate the new name. Then use the old and new name to
generate a rename command.  You could try something like this.

filename names pipe 'dir /b *.csv';
data files;
  infile names lrecl=3D256 truncover;
  input oldname $256.;
  if upcase(scan(oldname,-1,'.'))^=3D'CSV' then delete;
  newname =3D tranwrd(oldname,'A_','CC_');
  call system('rename '||quote(trim(oldname))||' '||
quote(trim(newname)));
run;

You can run the datastep as many times are you want without the CALL
SYSTEM command to make sure that you are finding the right files and
generating the right new name.

On Aug 16, 11:57=A0am, Paige Miller <paige.mil...@kodak.com> wrote:
> On Aug 16, 10:41=A0am, ash007 <ramsamyash...@gmail.com> wrote:
>
> > hello sas-users,
>
> > I have a folder which contains several file like : "A_X1.csv",
> > "A_X2.csv", "A_X3.csv" ... (I will not know how many file I have in
> > the folder).
>
> > How can I do a SAS program to rename each file and obtain :
> > "CC_X1.csv", "CC_X2.csv", "CC_X3.csv" ... (replace the A by CC).
>
> You probably are going to need to write a macro to do this. And for us
> to help, we would need to know what operating system you are using.
>
> --
> Paige Miller
> paige\dot\miller \at\ kodak\dot\com
0
Reply tom.abernathy (199) 8/17/2010 8:03:35 PM

On Aug 17, 10:03=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
> You will not need (or WANT) a macro to do this. =A0Read the names into a
> dataset and generate the new name. Then use the old and new name to
> generate a rename command. =A0You could try something like this.
>
> filename names pipe 'dir /b *.csv';
> data files;
> =A0 infile names lrecl=3D256 truncover;
> =A0 input oldname $256.;
> =A0 if upcase(scan(oldname,-1,'.'))^=3D'CSV' then delete;
> =A0 newname =3D tranwrd(oldname,'A_','CC_');
> =A0 call system('rename '||quote(trim(oldname))||' '||
> quote(trim(newname)));
> run;
>
> You can run the datastep as many times are you want without the CALL
> SYSTEM command to make sure that you are finding the right files and
> generating the right new name.
>
> On Aug 16, 11:57=A0am, Paige Miller <paige.mil...@kodak.com> wrote:
>
> > On Aug 16, 10:41=A0am, ash007 <ramsamyash...@gmail.com> wrote:
>
> > > hello sas-users,
>
> > > I have a folder which contains several file like : "A_X1.csv",
> > > "A_X2.csv", "A_X3.csv" ... (I will not know how many file I have in
> > > the folder).
>
> > > How can I do a SAS program to rename each file and obtain :
> > > "CC_X1.csv", "CC_X2.csv", "CC_X3.csv" ... (replace the A by CC).
>
> > You probably are going to need to write a macro to do this. And for us
> > to help, we would need to know what operating system you are using.
>
> > --
> > Paige Miller
> > paige\dot\miller \at\ kodak\dot\com

Thanks for the help.


but this command "call system('rename '||quote(trim(oldname))||' '||
quote(trim(newname)));" doesn't work.


ash_rmy.
0
Reply ramsamyashley (267) 8/25/2010 7:45:20 AM

On Aug 17, 10:03=A0pm, Tom Abernathy <tom.aberna...@gmail.com> wrote:
> You will not need (or WANT) a macro to do this. =A0Read the names into a
> dataset and generate the new name. Then use the old and new name to
> generate a rename command. =A0You could try something like this.
>
> filename names pipe 'dir /b *.csv';
> data files;
> =A0 infile names lrecl=3D256 truncover;
> =A0 input oldname $256.;
> =A0 if upcase(scan(oldname,-1,'.'))^=3D'CSV' then delete;
> =A0 newname =3D tranwrd(oldname,'A_','CC_');
> =A0 call system('rename '||quote(trim(oldname))||' '||
> quote(trim(newname)));
> run;
>
> You can run the datastep as many times are you want without the CALL
> SYSTEM command to make sure that you are finding the right files and
> generating the right new name.
>
> On Aug 16, 11:57=A0am, Paige Miller <paige.mil...@kodak.com> wrote:
>
> > On Aug 16, 10:41=A0am, ash007 <ramsamyash...@gmail.com> wrote:
>
> > > hello sas-users,
>
> > > I have a folder which contains several file like : "A_X1.csv",
> > > "A_X2.csv", "A_X3.csv" ... (I will not know how many file I have in
> > > the folder).
>
> > > How can I do a SAS program to rename each file and obtain :
> > > "CC_X1.csv", "CC_X2.csv", "CC_X3.csv" ... (replace the A by CC).
>
> > You probably are going to need to write a macro to do this. And for us
> > to help, we would need to know what operating system you are using.
>
> > --
> > Paige Miller
> > paige\dot\miller \at\ kodak\dot\com

Thanks for the help.


but this command "call system('rename '||quote(trim(oldname))||' '||
quote(trim(newname)));" doesn't work.


ash_rmy.
0
Reply ramsamyashley (267) 8/25/2010 7:45:25 AM

I've tried this :

FILENAME NAMES PIPE 'DIR "C:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\" /B
*.CSV';
DATA FILES;
  INFILE NAMES LRECL=256 TRUNCOVER;
  INPUT OLDNAME $256.;
  IF UPCASE(SCAN(OLDNAME,-1,'.'))^='CSV' THEN DELETE;
  NEWNAME = TRANWRD(OLDNAME,'A_','CC_');
  OLDNAMENEW = "C:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\"||
TRIM(OLDNAME);
		CALL EXECUTE
			(
				%SYSEXEC(RENAME 'OLDNAMENEW||TRIM(NEWNAME)'
			);
RUN;

but it doesn't work.

ash007.
0
Reply ash007 8/25/2010 8:34:46 AM

To debug just have the data step print the variables or commands to
the log (or better a file) and try running the command manually from
your DOS prompt to see what error message you get.  This is why using
the data step is so much easier to debug.

You might be having trouble because the file names are in lowercase
and your TRANWRD command will only replace the the uppercase A
followed by _ and so you are asking DOS to rename the file to the same
name.  You could use some other logic to manipulate this string. For
example: newname=3D'cc_'||substr(oldname,3);

You might be having trouble because DOS does not like to have the full
path used in the file names when using the rename command.  Try it and
find out.


In your sample code below you have mixed up macro logic and data step
code in this statement.

CALL EXECUTE(%SYSEXEC(RENAME 'OLDNAMENEW||TRIM(NEWNAME)');

The %SYSEXEC macro function will run before the data step (while SAS
is compiling/interpretting the statements) and so it will literally
try to have DOS execute the command RENAME 'OLDNAMENEW||TRIM(NEWNAME)'
which will not work because it only has one name listed and I doubt
that any of your files actually have that literal string as their
name.

The statement CALL EXECUTE takes a string variable or string literal
as its argument and in this code you have given it neither because the
%SYSEXEC function does not return a string. Even if it did you would
have needed to enclose it in double quotes so that SAS would parse it
as a string when interpretting your data step code.

Another way to get the operating system to run your commands is to use
a PIPE.  This is also handy when you are getting unexpected output
from your commands as you can read it back in a print it or store it
in a dataset.  For example if I try the syntax from the %SYSEXEC
function below I get this message:

1    filename xx pipe "RENAME 'OLDNAMENEW||TRIM(NEWNAME)'";
2    data _null_;
3      infile xx;
4      input; list;
5    run;

NOTE: The infile XX is:
      Unnamed Pipe Access Device,
      PROCESS=3DRENAME 'OLDNAMENEW||TRIM(NEWNAME)',
      RECFM=3DV,LRECL=3D256

Stderr output:
The syntax of the command is incorrect.
'TRIM' is not recognized as an internal or external command,
operable program or batch file.
NOTE: 0 records were read from the infile XX.
NOTE: DATA statement used (Total process time):
      real time           0.67 seconds
      cpu time            0.00 seconds



On Aug 25, 4:34=A0am, ash007 <ramsamyash...@gmail.com> wrote:
> I've tried this :
>
> FILENAME NAMES PIPE 'DIR "C:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\" /B
> *.CSV';
> DATA FILES;
> =A0 INFILE NAMES LRECL=3D256 TRUNCOVER;
> =A0 INPUT OLDNAME $256.;
> =A0 IF UPCASE(SCAN(OLDNAME,-1,'.'))^=3D'CSV' THEN DELETE;
> =A0 NEWNAME =3D TRANWRD(OLDNAME,'A_','CC_');
> =A0 OLDNAMENEW =3D "C:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\"||
> TRIM(OLDNAME);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 CALL EXECUTE
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 %SYSEXEC(=
RENAME 'OLDNAMENEW||TRIM(NEWNAME)'
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 );
> RUN;
>
> but it doesn't work.
>
> ash007.

0
Reply tom.abernathy (199) 8/25/2010 3:03:12 PM

thanks for the info.

how can I build a macro variable equal to  'DIR "C:\USERS\SUADEO
\DESKTOP\NOUVEAU DOSSIER\" /B *.CSV';

I don't know how to put the "

Thanks. ash


DATA _NULL_;
    FICHIERPIPE = CAT(
                            "'",
                            "DIR ",
                        ???, "&__LOCALISATION.", ???
                            " /B",
                            " *.",
                            "&__TYPE",
                            "'"
);



    CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
RUN; %PUT &__FICHIERPIPE.;

FILENAME NAMES PIPE "&__FICHIERPIPE.";
0
Reply ash007 8/25/2010 3:30:19 PM

Ash,

In answer to your original question, the following works for me:

%let path=3Dk:\art\;
options noxwait;

filename names pipe "dir /b &path.a_*.csv";
data files;
  infile names lrecl=3D256 truncover;
  input oldname $256.;
  if upcase(scan(oldname,-1,'.'))^=3D'CSV' then delete;
  oldname=3Doldname;
  newname =3D tranwrd(oldname,'A_','CC_');
  oldname=3Dcatt("&path.",oldname);
  call system('rename '||quote(trim(oldname))||' '||
quote(trim(newname)));
  *call system('rename '||trim(oldname)||' '||
trim(newname));
run;

HTH,
Art
-----------------
On Aug 25, 11:30=A0am, ash007 <ramsamyash...@gmail.com> wrote:
> thanks for the info.
>
> how can I build a macro variable equal to =A0'DIR "C:\USERS\SUADEO
> \DESKTOP\NOUVEAU DOSSIER\" /B *.CSV';
>
> I don't know how to put the "
>
> Thanks. ash
>
> DATA _NULL_;
> =A0 =A0 FICHIERPIPE =3D CAT(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "DIR ",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ???, "&__LOCALISATION.", =
???
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " /B",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " *.",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "&__TYPE",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'"
> );
>
> =A0 =A0 CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
> RUN; %PUT &__FICHIERPIPE.;
>
> FILENAME NAMES PIPE "&__FICHIERPIPE.";

0
Reply art297 (4237) 8/25/2010 6:14:45 PM

On Aug 25, 8:14=A0pm, Arthur Tabachneck <art...@netscape.net> wrote:
> Ash,
>
> In answer to your original question, the following works for me:
>
> %let path=3Dk:\art\;
> options noxwait;
>
> filename names pipe "dir /b &path.a_*.csv";
> data files;
> =A0 infile names lrecl=3D256 truncover;
> =A0 input oldname $256.;
> =A0 if upcase(scan(oldname,-1,'.'))^=3D'CSV' then delete;
> =A0 oldname=3Doldname;
> =A0 newname =3D tranwrd(oldname,'A_','CC_');
> =A0 oldname=3Dcatt("&path.",oldname);
> =A0 call system('rename'||quote(trim(oldname))||' '||
> quote(trim(newname)));
> =A0 *call system('rename'||trim(oldname)||' '||
> trim(newname));
> run;
>
> HTH,
> Art
> -----------------
> On Aug 25, 11:30=A0am, ash007 <ramsamyash...@gmail.com> wrote:
>
> > thanks for the info.
>
> > how can I build a macro variable equal to =A0'DIR "C:\USERS\SUADEO
> > \DESKTOP\NOUVEAU DOSSIER\" /B *.CSV';
>
> > I don't know how to put the "
>
> > Thanks. ash
>
> > DATA _NULL_;
> > =A0 =A0 FICHIERPIPE =3D CAT(
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "DIR ",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ???, "&__LOCALISATION."=
, ???
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " /B",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " *.",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "&__TYPE",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'"
> > );
>
> > =A0 =A0 CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
> > RUN; %PUT &__FICHIERPIPE.;
>
> > FILENAME NAMES PIPE "&__FICHIERPIPE.";

thanks. it is working very well !
0
Reply ramsamyashley (267) 8/25/2010 7:38:26 PM

Usually there is no need to use a DATA _NULL_ to manipulate macro
variables.
Just use the %LET statement.

To get a quote inside of quoted string in SAS syntax use two quote
character inside the string.

%let dir=3DC:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\;
%let xx=3D"DIR ""&dir"" /B *.CSV";

You can also use the QUOTE function.

%let xx=3D%sysfunc(quote(DIR "&dir" /B *.CSV));


On Aug 25, 11:30=A0am, ash007 <ramsamyash...@gmail.com> wrote:
> thanks for the info.
>
> how can I build a macro variable equal to =A0'DIR "C:\USERS\SUADEO
> \DESKTOP\NOUVEAU DOSSIER\" /B *.CSV';
>
> I don't know how to put the "
>
> Thanks. ash
>
> DATA _NULL_;
> =A0 =A0 FICHIERPIPE =3D CAT(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "DIR ",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ???, "&__LOCALISATION.", =
???
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " /B",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " *.",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "&__TYPE",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'"
> );
>
> =A0 =A0 CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
> RUN; %PUT &__FICHIERPIPE.;
>
> FILENAME NAMES PIPE "&__FICHIERPIPE.";

0
Reply tom.abernathy (199) 8/26/2010 5:13:13 AM

On Aug 26, 7:13=A0am, Tom Abernathy <tom.aberna...@gmail.com> wrote:
> Usually there is no need to use a DATA _NULL_ to manipulate macro
> variables.
> Just use the %LET statement.
>
> To get a quote inside of quoted string in SAS syntax use two quote
> character inside the string.
>
> %let dir=3DC:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\;
> %let xx=3D"DIR ""&dir"" /B *.CSV";
>
> You can also use the QUOTE function.
>
> %let xx=3D%sysfunc(quote(DIR "&dir" /B *.CSV));
>
> On Aug 25, 11:30=A0am, ash007 <ramsamyash...@gmail.com> wrote:
>
> > thanks for the info.
>
> > how can I build a macro variable equal to =A0'DIR "C:\USERS\SUADEO
> > \DESKTOP\NOUVEAU DOSSIER\" /B *.CSV';
>
> > I don't know how to put the "
>
> > Thanks. ash
>
> > DATA _NULL_;
> > =A0 =A0 FICHIERPIPE =3D CAT(
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "DIR ",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ???, "&__LOCALISATION."=
, ???
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " /B",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " *.",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "&__TYPE",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'"
> > );
>
> > =A0 =A0 CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
> > RUN; %PUT &__FICHIERPIPE.;
>
> > FILENAME NAMES PIPE "&__FICHIERPIPE.";

cool. thanks.
0
Reply ramsamyashley (267) 8/26/2010 10:46:40 AM

On Aug 26, 5:46=A0am, ash007 <ramsamyash...@gmail.com> wrote:
> On Aug 26, 7:13=A0am, Tom Abernathy <tom.aberna...@gmail.com> wrote:
>
>
>
>
>
> > Usually there is no need to use a DATA _NULL_ to manipulate macro
> > variables.
> > Just use the %LET statement.
>
> > To get a quote inside of quoted string in SAS syntax use two quote
> > character inside the string.
>
> > %let dir=3DC:\USERS\SUADEO\DESKTOP\NOUVEAU DOSSIER\;
> > %let xx=3D"DIR ""&dir"" /B *.CSV";
>
> > You can also use the QUOTE function.
>
> > %let xx=3D%sysfunc(quote(DIR "&dir" /B *.CSV));
>
> > On Aug 25, 11:30=A0am, ash007 <ramsamyash...@gmail.com> wrote:
>
> > > thanks for the info.
>
> > > how can I build a macro variable equal to =A0'DIR "C:\USERS\SUADEO
> > > \DESKTOP\NOUVEAU DOSSIER\" /B *.CSV';
>
> > > I don't know how to put the "
>
> > > Thanks. ash
>
> > > DATA _NULL_;
> > > =A0 =A0 FICHIERPIPE =3D CAT(
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'",
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "DIR ",
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ???, "&__LOCALISATION=
..", ???
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " /B",
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " *.",
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "&__TYPE",
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "'"
> > > );
>
> > > =A0 =A0 CALL SYMPUT('__FICHIERPIPE',TRIM(FICHIERPIPE));
> > > RUN; %PUT &__FICHIERPIPE.;
>
> > > FILENAME NAMES PIPE "&__FICHIERPIPE.";
>
> cool. thanks.- Hide quoted text -
>
> - Show quoted text -

It will be  easy if you have SAS 9.2 ..... Just use rename function
inside the datastep to rename an external file.

/* rename a PC file */
data _null_;
rc=3D rename('C:\temp\A_X1.csv','C:\temp\A_X1.csv','file');
run;

Sarath
www.studysas.blogspot.com

0
Reply learnsasonline (22) 10/14/2010 1:10:23 AM

16 Replies
357 Views

(page loaded in 0.166 seconds)

Similiar Articles:













7/22/2012 7:17:53 PM


Reply: