Create ID Variable From FILENAME

Reply
Contributor
Posts: 20

Create ID Variable From FILENAME

The code below reads multiple csv files into a single SAS dataset. How can I create an ID variable using the name of the csv files?

FILENAME myfiles ("C:\path\*.csv");

DATA mysasdata;

  INFILE myfiles DSD MISSOVER FIRSTOBS=8;

    INPUT record date :mmddyy10. time :time8. BG MeterSN $;

  RUN;

Thanks,

Raphael

Super User
Super User
Posts: 6,500

Re: Create ID Variable From FILENAME

Look at the FILENAME option on INFILE statement.  Note that you will need to make two variables as the one referenced in the INFILE statement will be dropped.

Also note that FIRSTOBS will not work correctly in this case as it will only skip the beginning of the first file it opens.

Ask a Question
Discussion stats
  • 1 reply
  • 171 views
  • 0 likes
  • 2 in conversation