04-06-2017 11:55 AM - edited 04-06-2017 12:54 PM
I am trying to import 79 different SAS datasets and export them as .dta files. Part of the issue I am having is that the .sas7bdat file names are not valid SAS dataset names--they contain only numeric characters.
I tried to write code that would at least import one dataset and save it out as a .dta and then create a loop to go through the rest of the SAS datasets, but I cannot even get past the first step.
%let folder = C:\Example folder;
proc printto log="&folder.\SAS files\Logs\01 Convert SAS files to dta.log" new; run; libname sasinput "&folder.\Natives"; options validvarname=any; proc export data=sasinput.01095552 outfile= "&folder.\SAS files\Output\01095552.dta" REPLACE; run; proc printto; run;
It seems from researching that I need to specify the system option validvarname=any but it does not appear that I am specifying it correctly.
I am looking to loop through SAS datasets sequentially numbered beginning with 01095552.sas7bdat and ending with 01095630.sas7bdat. I am having a lot of trouble figuring out what I am doing wrong.
Thank you for any help. If you could not tell I am fairly inexperienced with SAS, although I have a lot of STATA experience.
04-06-2017 12:47 PM
Two questions: 1. You use the macro variable &folder, but don't show the code that created that macro variable and
2. validvarname=any doesn't apply to SAS dataset names. They CAN'T begin with a number or include any special characters (other than an underscore).
I would guess that the files were either renamed, or created by a program outside of SAS.
My suggestion would be to write a program that renames the files, keeping them as is, but beginning with an underscore. Then you should be able to export them.
Art, CEO, AnalystFinder.com
04-06-2017 01:11 PM
Yes, forgot to copy the line of code that generates the macro variable &folder in my post above (fixed now).
Renaming the files makes my code work. Would've liked to have avoided it, but thankfully isn't a big deal in the end. Thanks for the help!