Libname Libsas 'E:\libsas\Itop';
Filename FichCsv2 'O:\Sc-Performance\PFI\ITOP\input_data\SCCM\Itop_Extraction_SCCM2012_lab.csv' ENCODING="utf-8";
%macro import_csv(outf,outds);
%put outf=&outf;
%let filrf=myfile;
%put filrf=&filrf;
%if %sysfunc(fileexist(&outf)) %then %do;
%let rc=%sysfunc(filename(filrf,&outf));
%let fid=%sysfunc(fopen(&filrf));
%if &fid > 0 %then %do;
%let rc=%sysfunc(fread(&fid));
%let rc=%sysfunc(fget(&fid,mystring));
%let rc_close=%sysfunc(fclose(&fid));
%if &rc = 0 %then %do;
proc import file="&outf." out=&outds
DBMS=DLM REPLACE;
Delimiter=';';
Guessingrows=32767;
Getnames=Yes;
run;
%end;
%else %do;
%put Fichier &outf. importation impossible fichier vide.;
Data _NULL_;
Date = today();
Format Date yymmdd10.;
File Sortie Notitles Mod;
put @50 "En date du: " Date +(-1)"," /;
put @10 "Le fichier &outf est vide.";
run;
%end;
%end;
%let rc=%sysfunc(filename(filrf));
%end;
%else %put fichier existe pas;
%mend import_csv;
%import_csv(O:\Sc-Performance\PFI\ITOP\input_data\SCCM\Itop_Extraction_SCCM2012_lab.csv,Libsas.ItopSCCMLAB);
*%import_csv("&Fich2.",Libsas.ItopSCCMLAB);
Can not pass the filename with encoding. is there a way to pass him the filename or some other way because I have to keep the encoding.
The file exist portion doesn't need to change, they can be mutually exclusive events.
What happens if you use the filename reference instead of the file path?
proc import file=fichCsv2 out=&outds
DBMS=DLM REPLACE;
Delimiter=';';
Guessingrows=32767;
Getnames=Yes;
run;
@lavm01 wrote:
Libname Libsas 'E:\libsas\Itop'; Filename FichCsv2 'O:\Sc-Performance\PFI\ITOP\input_data\SCCM\Itop_Extraction_SCCM2012_lab.csv' ENCODING="utf-8"; %macro import_csv(outf,outds); %put outf=&outf; %let filrf=myfile; %put filrf=&filrf; %if %sysfunc(fileexist(&outf)) %then %do; %let rc=%sysfunc(filename(filrf,&outf)); %let fid=%sysfunc(fopen(&filrf)); %if &fid > 0 %then %do; %let rc=%sysfunc(fread(&fid)); %let rc=%sysfunc(fget(&fid,mystring)); %let rc_close=%sysfunc(fclose(&fid)); %if &rc = 0 %then %do; proc import file="&outf." out=&outds DBMS=DLM REPLACE; Delimiter=';'; Guessingrows=32767; Getnames=Yes; run; %end; %else %do; %put Fichier &outf. importation impossible fichier vide.; Data _NULL_; Date = today(); Format Date yymmdd10.; File Sortie Notitles Mod; put @50 "En date du: " Date +(-1)"," /; put @10 "Le fichier &outf est vide."; run; %end; %end; %let rc=%sysfunc(filename(filrf)); %end; %else %put fichier existe pas; %mend import_csv; %import_csv(O:\Sc-Performance\PFI\ITOP\input_data\SCCM\Itop_Extraction_SCCM2012_lab.csv,Libsas.ItopSCCMLAB); *%import_csv("&Fich2.",Libsas.ItopSCCMLAB);
Can not pass the filename with encoding. is there a way to pass him the filename or some other way because I have to keep the encoding.
I know, I already tried that. Me it's more in the macro, the outf that does not recognize the encoding.
%import_csv(FichCsv2,Libsas.ItopSCCMLAB);
I tried with that but it does not work.
I can only comment on what you've posted.
Your encoding is not a parameter within PROC IMPORT that I can see, and you don't pass it in any form so I'm not sure what you're expecting. I don't see the encoding in the macro anywhere...and the section below - myfile is never defined within what you've posted so that may be problematic.
You could declare a filename statement within the macro and use that similar to the code I posted earlier, instead of passing the path to PROC IMPORT, pass the filename reference instead.
%put outf=&outf;
%let filrf=myfile;
%put filrf=&filrf;
@lavm01 wrote:
I know, I already tried that. Me it's more in the macro, the outf that does not recognize the encoding.
I agree with you, but the marcro checks the file and also checks if it is possible to import the file. That is why the outf contains the path of the CSV as well as the encoding.
The file exist portion doesn't need to change, they can be mutually exclusive events.
Your macro is already generating one or more steps, so just use a data step instead of macro code to call the various functions, (fileexist(),filename(),fopen(),etc.).
It will be a LOT easier to debug.
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!
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.