BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I need to write a program in SAS that would look for a physical file in a folder and if it is available then look for the file name and look if it matches it with the file name in an excel sheet then write a value in excel sheet with a letter “e” .



How can I do it?
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
For the "physical file detection", you can use the FILEEXIST call function, either in a DATA step or using %SYSFUNC and coding a macro. Then perform additional processing when you find the file.

Regarding the Excel question; suggest searching the SAS support http://support.sas.com/ website using either the site SEARCH facility or the Google advanced argument below:

update excel worksheet site:sas.com


Scott Barry
SBBWorks, Inc.
Patrick
Opal | Level 21
Hi
The excel workbook used in this example for windows is:"c:\SASUSER\test.xls".
The workbook has a sheet named "sheet1" with 2 column headings (A1: myfiles, B1: exist).
HTH
Patrick


/* read files in directory */
filename myfiles pipe 'dir "c:\SASUSER\*.sas" /B/ON';
data FilesInDir;
infile myfiles truncover;
input myfiles $50.;
put _infile_;
run;
filename myfiles clear;

/* Update Excel column 'exist' if matching filenames */
LIBNAME WrkBk EXCEL "c:\SASUSER\test.xls" scan_text=no;
proc sql;
update wrkbk.'sheet1$'n as xlssheet
set exist='e'
where upcase(strip(xlssheet.myfiles)) in (select upcase(strip(myfiles)) from FilesInDir)
;
select * from wrkbk.'sheet1$'n as xlssheet ;
quit;
LIBNAME WrkBk clear;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 563 views
  • 0 likes
  • 3 in conversation