BookmarkSubscribeRSS Feed
mjcochran
Calcite | Level 5

Hello,

 

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.

 

2 REPLIES 2
art297
Opal | Level 21

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

 

mjcochran
Calcite | Level 5

Hi Art,

 

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! 

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
  • 2 replies
  • 871 views
  • 0 likes
  • 2 in conversation