Hello,
I'm using SAS base 9.4.
In my library named "source", I have a dataset called "X_test".
In this dataset, there is a column called "image_name" which contains the names of an image stored in my folder.
I'm trying to write a macro that for each "image_name", go to a source folder, select the image and copy it into an other folder.
Here the code I wrote but I don't know how to said to look in each column to get the file name.
The error is that SAS doesn't have the image_name. I got "File incorrect" because image_name=. for SAS.
Anyone have a solution to suggest me ?
data _null_; length source destin $8; retain indir "C:/Users/Me/image_test_sas" outdir "C:/Users/Me/image_copy"; if fileexist (indir || '/' || image_name) then do; rc = filename (source, indir || '/' || image_name); rc = filename (destin, outdir || '/' || image_name); rc = fcopy (source, destin); if rc ne 0 then do; msg = sysmsg(); putlog msg; end; rc = filename (source); call missing (source); rc = filename (destin); call missing (destin); end; run;
Thank you
I think you are missing a SET statement.
data _null_;
set malib.x_test2;
...
run;
What is wrong with the code you are showing? Are there errors in the log? If so, show us the ENTIRE log for this data step (every single line, every single character, with nothing omitted or removed).
Ok, I've upadated my post.
I didn't run my code because I know that it is incomplete.
I don't know how to select image_name for each line of my dataset inside my code.
I think you are missing a SET statement.
data _null_;
set malib.x_test2;
...
run;
It works!
Thank you very much! I think I wasn't able to see the missing instructions.
I put the right code here in case someone is interested in :
data _null_;
set "<name_of_dataset>";
length source destin $8;
retain indir "<source-folder>" outdir "<destin-folder>";
if fileexist (indir || '/' || image_name) then do;
rc = filename (source, indir || '/' || image_name);
rc = filename (destin, outdir || '/' || image_name);
rc = fcopy (source, destin);
if rc ne 0 then do;
msg = sysmsg();
putlog msg;
end;
rc = filename (source); call missing (source);
rc = filename (destin); call missing (destin);
end;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.