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

Hi all

 

I am trying to use a do loop to upload multiple data files that vary by a trailing integer (e.g. dataset1.dat, dataset2.dat, etc)

 

I tried using a macro, but have had issues. From the way the editor does not bold the data procedure it seems like it is not recognizing it as a command within the marco. Anyone have suggestions?

 

filename SIPP1 "C:\...SIPP\l08puw1.dat";

filename SIPP2 "C:\...SIPP\l08puw2.dat";

filename SIPP3 "C:\...SIPP\l08puw3.dat";

filename SIPP4 "C:\...SIPP\l08puw4.dat";

 

%macro uploadSIPP;

%local i;

%do i=1 %to 4;

   data SIPPRAW&i;

   INFILE SIPP&i PAD LRECL=2341;

   INPUT

   SSUSEQ 1- 5

   SSUID $ 6- 17

   SPANEL 18- 21

   ...

   FILLER 2338-2340;

RUN;

%end;

%mend uploadSIPP;

%uploadSIPP;

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Your code worked fine for me. You'd have to show us your log for anyone to know what your problem is.

 

Art, CEO, AnalystFinder.com

View solution in original post

12 REPLIES 12
collinelliot
Barite | Level 11

You can use one filename that refers to multiple files. If they are all the same structure, and in your example it looks like they are, this would be much easier.

 

filename all_files ('file1.txt' file2.txt' etc...);

collinelliot
Barite | Level 11

That said, I wouldn't rely on the editor syntax highlighitng to tell you if it's correct code. Are you getting an error when you run what you? What are the issues?

art297
Opal | Level 21

Your code worked fine for me. You'd have to show us your log for anyone to know what your problem is.

 

Art, CEO, AnalystFinder.com

hoops581
Fluorite | Level 6

Weird. Now it works for me too. I guess I got caught up in the editor labeling. I also rebooted SAS so maybe that helped.

 

Thanks for the confirmation. I was driving myself crazy!

hoops581
Fluorite | Level 6

I had no idea that could be done. When I try however I am getting this error:

 

filename SIPP_FILES ('l08puw1.dat' 'l08puw2.dat' 'l08puw3.dat');

ERROR: Invalid logical name.

ERROR: Error in the FILENAME statement.

 

I have a feeling I am missing a basic point.

collinelliot
Barite | Level 11

You'll need the full path names for that to work:

 

filename SIPP_FILES ('somepath\l08puw1.dat' 'somepath\l08puw2.dat' 'somepath\l08puw3.dat');

hoops581
Fluorite | Level 6

Even though it appears the old code works, I am intriqued by the naming of multiple files, but am still getting an error.

 

1047 filename SIPP_FILES ('C:\Users\...\Desktop\SIPP\l08puw1.dat'

1047! 'C:\Users\...\Desktop\SIPP\l08puw2.dat');

ERROR: Invalid logical name.

ERROR: Error in the FILENAME statement.

 

collinelliot
Barite | Level 11

The error is saying that the path and or file is not valid.

 

Are you replacing the actual path with "..." or is that your actual syntax?

 

 

hoops581
Fluorite | Level 6

It appears SAS did not like the name SIPP_FILES. When I changed the name to SIPP_FIL the code worked. When I switched it back to SIPP_FILES it got angry again. Guess I should always remember to check the name.

 

Thank you for the tip by the way!

collinelliot
Barite | Level 11

Note that you can use wildcards, too, so you could just replace the # with "*" and really limit your typing. Just make sure you're not pulling in something you don't want.

ballardw
Super User

@hoops581 wrote:

It appears SAS did not like the name SIPP_FILES. When I changed the name to SIPP_FIL the code worked. When I switched it back to SIPP_FILES it got angry again. Guess I should always remember to check the name.

 

Thank you for the tip by the way!


FILENAME and LIBNAME are both limited to 8 characters in the reference name so since SIPP_FILES has 10 characters that is an error.

hoops581
Fluorite | Level 6

Good to know! I thought it was perhaps something related to having "FILE" in the name. That will save me many errors in the future. Thank you

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 3473 views
  • 3 likes
  • 4 in conversation