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.
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.
Ah, simple is best. Thanks!
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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.