Basically, I want to read two columns from a csv file and create a text file for each record. The text file name is the first column and I want to write the second column to this text file.
CSV file records sample:
column1 column2
txtfile1 file1data
txtfile2 file2data
txtfile3 file3data
txtfile4 file4data
<**** start code ****>
%LET CSVFile_FullPath=C:\projects\csvFile.csv;
%LET Directory_FullPath=C:\projects\txtFilesFolders;
data _null_;
infile "&CSVFile_FullPath" dsd dlm=',' firstobs=2 truncover missover;
input col1 :$8. col2 :$9.;
/*build the text file name*/
txtFile="&Directory_FullPath"||"\"||col1||".txt";
/* pass txt file name and data to a macro*/
%WriteTo(txtFile,col2);
run;
/*parms: file name and data*/
%macro WriteTo(fle,dta);
%let f="&fle";
data _null_;
file &f mod;
put &dta;
run;
%mend WriteTo;
<**** end code ****>
The file that is being created is txtFile.txt, instead of txtfile1.txt, txtfile2.txt, txtfile3.txt, txtfile4.txt. It seems that the macro is not resolving the macro variable for some reason.
I appreciate any help.
CSV file records sample:
column1 column2
txtfile1 file1data
txtfile2 file2data
txtfile3 file3data
txtfile4 file4data
<**** start code ****>
%LET CSVFile_FullPath=C:\projects\csvFile.csv;
%LET Directory_FullPath=C:\projects\txtFilesFolders;
data _null_;
infile "&CSVFile_FullPath" dsd dlm=',' firstobs=2 truncover missover;
input col1 :$8. col2 :$9.;
/*build the text file name*/
txtFile="&Directory_FullPath"||"\"||col1||".txt";
/* pass txt file name and data to a macro*/
%WriteTo(txtFile,col2);
run;
/*parms: file name and data*/
%macro WriteTo(fle,dta);
%let f="&fle";
data _null_;
file &f mod;
put &dta;
run;
%mend WriteTo;
<**** end code ****>
The file that is being created is txtFile.txt, instead of txtfile1.txt, txtfile2.txt, txtfile3.txt, txtfile4.txt. It seems that the macro is not resolving the macro variable for some reason.
I appreciate any help.