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

Hello,

I am trying to import multiple text file in R and have try to follow what was advise in a similar post but it's not working for me, I do not know what I am doing wrong. Below the link 's post  I am referring to

 

https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-...

 

Here is the path of my files

Blandine_0-1602801362609.png

 

Below my code

 

/*Importing multiple text files */
%let path=C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task 8_Back-casting\NBI Data from Fhwa site\ID_All years;

%MACRO IMPORT_TXT(FILENAME=ID,OUTFILENAME=ID);
proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task 8_Back-casting\NBI Data from Fhwa site\ID_All years\ID..txt" dbms=dlm out=IDAHO.&ID replace;
delimiter='';
run;
%MEND;

/* Calling Macro to import First file */
%IMPORT_TXT(FILENAME=ID00,OUTFILENAME=ID00);

/* Calling Macro to import second file */
%IMPORT_TXT(FILENAME=ID01,OUTFILENAME=ID01);

 

 

And the log error

168 %let path=C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task 8_Back-casting\NBI
168! Data from Fhwa site\ID_All years;
169
170 %MACRO IMPORT_TXT(FILENAME=ID,OUTFILENAME=ID);
171 proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task
171! 8_Back-casting\NBI Data from Fhwa site\ID_All years\ID..txt" dbms=dlm out=IDAHO.&ID replace;
172 delimiter='';
173 run;
174 %MEND;
175
176 /* Calling Macro to import First file */
177 %IMPORT_TXT(FILENAME=ID00,OUTFILENAME=ID00);
WARNING: Apparent symbolic reference ID not resolved.
ERROR: "IDAHO." is not a valid name.
NOTE 137-205: Line generated by the invoked macro "IMPORT_TXT".
1 proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task
1 ! 8_Back-casting\NBI Data from Fhwa site\ID_All years\ID..txt" dbms=dlm out=IDAHO.&ID replace;
-
22
1 ! delimiter=''; run;
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS,
DEBUG, FILE, OUT, REPLACE, TABLE, _DEBUG_.

NOTE: Line generated by the invoked macro "IMPORT_TXT".
1 proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task
1 ! 8_Back-casting\NBI Data from Fhwa site\ID_All years\ID..txt" dbms=dlm out=IDAHO.&ID replace;
-
200
1 ! delimiter=''; run;
ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

WARNING: Apparent symbolic reference ID not resolved.
ERROR: Invalid data set name IDAHO..
NOTE: The SAS System stopped processing this step because of errors.
178
179 /* Calling Macro to import second file */
180 %IMPORT_TXT(FILENAME=ID01,OUTFILENAME=ID01);


WARNING: Apparent symbolic reference ID not resolved.
ERROR: "IDAHO." is not a valid name.
NOTE 137-205: Line generated by the invoked macro "IMPORT_TXT".
1 proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task
1 ! 8_Back-casting\NBI Data from Fhwa site\ID_All years\ID..txt" dbms=dlm out=IDAHO.&ID replace;
-
22
1 ! delimiter=''; run;
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS,
DEBUG, FILE, OUT, REPLACE, TABLE, _DEBUG_.

NOTE: Line generated by the invoked macro "IMPORT_TXT".
1 proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task
1 ! 8_Back-casting\NBI Data from Fhwa site\ID_All years\ID..txt" dbms=dlm out=IDAHO.&ID replace;
-
200
1 ! delimiter=''; run;
ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds

WARNING: Apparent symbolic reference ID not resolved.
ERROR: Invalid data set name IDAHO..
NOTE: The SAS System stopped processing this step because of errors.

 

 

 

thanks for your help

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
CurtisMackWSIPP
Lapis Lazuli | Level 10

It looks like you are confusing the macro parameter name with its default name.

I think you want something like this, although this is difficult to test outside of your environment.

 


%MACRO IMPORT_TXT(FILENAME=ID,OUTFILENAME=ID);
proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task 8_Back-casting\NBI Data from Fhwa site\ID_All years\&FILENAME..txt" dbms=dlm out=&OUTFILENAME replace;
delimiter='';
run;
%MEND;

View solution in original post

2 REPLIES 2
CurtisMackWSIPP
Lapis Lazuli | Level 10

It looks like you are confusing the macro parameter name with its default name.

I think you want something like this, although this is difficult to test outside of your environment.

 


%MACRO IMPORT_TXT(FILENAME=ID,OUTFILENAME=ID);
proc import datafile="C:\Users\bmrg2\Box Sync\Mizzou 2019\Research\RBI Project\Task 8_Back-casting\NBI Data from Fhwa site\ID_All years\&FILENAME..txt" dbms=dlm out=&OUTFILENAME replace;
delimiter='';
run;
%MEND;
andreas_lds
Jade | Level 19

Start with normal sas-code without any macros and macro-variables.

Your problem is an evergreen, so you will find some useful hints using the search-box.