BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sajid01
Meteorite | Level 14

Looks like your SAS server is on a Unix/Linux machine and you are trying to save file on your windows desktop./laptop.
Try saving the file into your workspace on the Linux machine. The following code will give the path of your workspace on server. Anything here would disappear once your session closes.

%let temp_path=%sysfunc(pathname(WORK));
%put &=temp_path;
/* save your file to &temp_path./your_file.txt */

You can save your file to the above location

 

 

Boswser
Obsidian | Level 7
Thank you Sajid, sorry I missed this response!

So I’m definitely new to macros, bear with me. 🙂 I’m not exactly sure what values to put where. Does this look correct?

%let temp_path=%sysfunc(/sas/work/saswork3/SAS_work21C400006785_dr877/SAS_workA1B200006785_dr877/TESTFILE.txt(WORK));

(And sorry—not sure what I should be replacing with what in this second part?)

%put &=temp_path;/* save your file to &temp_path./your_file.txt *
jimbarbour
Meteorite | Level 14

It might look something like the below.  Notice the change I made to the FILENAME.  The path is brought in via a macro variable.

 

%let temp_path=%sysfunc(pathname(WORK));
%put &=temp_path;

FILENAME Out_File "&temp_path/my_file.txt" LRECL=46;

Data _NULL_;
    Set  Have;
    File Out_File;
    Put  @1  ID
            @10  First_Name
            @35  Middle_Initial
            @36  Last_Name
             ;
RUN;

Jim

 

Boswser
Obsidian | Level 7
Thanks Jim! I guess the part I am confused about is what (if anything) I am replacing “PATHNAME” with.

Should I replace it with “/sas/work/saswork3/SAS_work21C400006785_dr877/SAS_workA1B200006785_dr877/TESTFILE.txt”, with the desktop filepath (C:\Users...etc), or just call it whatever I want?
Sajid01
Meteorite | Level 14

Hello @Boswser 

1.The pathname(WORK) gives the full path  of your work directory/temp space.  This is a location on the server and not on desktop.
2.The full path of the work directory is a dynamic value and it changes with your session. Therefore you should only use the macro and not the physical name. Thus you have the following

/* This line extracts or finds the path*/
%let temp_path=%sysfunc(pathname(WORK));
/* when you want the filename use this :"&temp_path/my_file.txt" 
for example thanks to @jimbarbour   */
FILENAME Out_File "&temp_path/my_file.txt" LRECL=46;

3.Your SAS Server is on Unix and EG on your desktop. Your code executes on the server
Typically desktop locations under your scenario are not accessible to the code running ion the server.
Thus one cannot use desktop/laptops paths like c:\

jimbarbour
Meteorite | Level 14

You should literally code it with the literal WORK.  WORK is the libname.  SAS will then retrieve the path for you.

%let temp_path=%sysfunc(pathname(WORK));

Jim

Boswser
Obsidian | Level 7
****EDIT

Thanks so much to you both! My original reply here pointed out I couldn’t call on the macro path in the COPY FILES step.

After opening my eyes, I saw there was a checkbox for ‘resolve macro variables’ in the COPY FILES box.

Success!!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 21 replies
  • 2105 views
  • 7 likes
  • 4 in conversation