0

I am trying to write code in SAS which will loop over a folder full of CSVs. The "Data" folder in the linked file (testcsv.zip) is a sample of those files (6 of them), but in actuality, I have about 6,000 CSVs that I need to iterate over. Each file is formatted the same way, such as:

example table

I need to loop over each of the CSVs in the folder, and do the following:

  • output VAR15 (this is the Event identifier - it's a repeated variable in each file, but unique between files)
  • output VAR16 (this is a "distance" variable - it's a repeated variable in each file, and there are 10 different distances for each event [50,100,150,etc.])
    • run proc univariate for:
      • VAR4 (elevation)
      • VAR5 (intensity)
      • VAR14 (acd)

and output all statistics available (mean, std, kurtosis, mode, etc. etc.) for each of these variables. So I am looking for an output table that looks like:

Outputexample

The output would have 6,000 rows (one row for each CSV file) and x number of columns (would like all statistics from the univariate command - I believe that is 45, so 45x3 variables + event + distance = 137 columns total).

I'm a newbie to SAS and all the people I know that work with SAS have had trouble coming up with a solution for this problem. Macros have been suggested, but I am having trouble getting very far in writing one. Any help in getting started would be very much appreciated. Other approach suggestions using R or Matlab are welcome! Thank you!

testcsv.zip

luna2000
  • 45
  • 1
  • 2
  • 6
  • 1
    Your question is too broad and too much asking for code, but I think the linked duplicate should get you started with the input side. I would read them all into one large dataset using the FILENAME= option on the infile statement to store which file they were input, then do your analysis BY that variable. – Joe Mar 24 '15 at 19:20
  • 1
    There are also a few other questions; search `[sas] csv loop' for example and you'll find quite a few related topics. [This one](http://stackoverflow.com/questions/20834839/sas-do-while-loop-not-iterating) for example shows something a bit closer to what it seems like you're asking for, though it's not how I'd do it. – Joe Mar 24 '15 at 19:25
  • Read all into one file and then use a single proc univariate to process the files. Hope this link helps: https://communities.sas.com/docs/DOC-10426 – Reeza Mar 25 '15 at 04:30

0 Answers0