BookmarkSubscribeRSS Feed
m852
Calcite | Level 5

Hello,

I have a SAS pgm written in legacy SAS that was saved as a txt file.  I have imported it to SAS studio, but I cannot find how to convert this txt file to a .sas pgm.  Can anyone advise?  It is thousands of lines so retyping is not an option.

Thanks.

4 REPLIES 4
Tom
Super User Tom
Super User

No need to "convert" it.  Just change its name.  SAS/Studio has a RENAME option.

 

For some reason SAS/Studio makes a big deal of the extension used on the filename.  Not sure why.

m852
Calcite | Level 5

Ah, simple is best. Thanks!

Amir
PROC Star

Hi,

 

I'm glad you've got a solution. Marking @Tom's post as the solution makes it easier for others to find if they have a similar question, and it gives him the credit - not that he needs the points in this community! 🤣

 

 

Thanks & kind regards,

Amir.

Ksharp
Super User

The following code is changing all the .TXT files under a fold into .SAS files.

%let path_in=  D:\temp\02_table ;  *the pathname for txt files;
%let path_out=  D:\temp\02_table ;  *the pathname for sas files;


filename x pipe "dir &path_in.\*.txt /s /b";
data x;
 infile x truncover;
 input old $2000.;
new=cats(prxchange('s/\w+$//',1,strip(old)),'sas');
rc=rename(strip(old),strip(new),'file');
run;

And an alternative code by using sas capability: (especially your file name is utf8 encoding)



/******For UTF-8 编码的文件名***********/
%let path_in= D:\temp\02_table ;  *the pathname for txt files;
%let path_out= D:\temp\02_table ;  *the pathname for sas files;


data _null_;
length fname old new $ 200;
rc=filename('x',"&path_in.");
did=dopen('x');
do i=1 to dnum(did);
 fname=dread(did,i);
 if lowcase(strip(scan(fname,-1,'.')))='txt' then do;
   old=cats("&path_in",'\',fname);
   new=cats(prxchange('s/\w+$//',1,strip(old)),'sas');
   rc=rename(strip(old),strip(new),'file');
 end;
end;
run;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 967 views
  • 4 likes
  • 4 in conversation