BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mmoriss
Calcite | Level 5

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.

 

mmoriss_0-1680618625774.png

 

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I think you are missing a SET statement.

 

data _null_;
    set malib.x_test2;
    ...
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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).

--
Paige Miller
mmoriss
Calcite | Level 5

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.

PaigeMiller
Diamond | Level 26

I think you are missing a SET statement.

 

data _null_;
    set malib.x_test2;
    ...
run;
--
Paige Miller
mmoriss
Calcite | Level 5

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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