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-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
  • 21 replies
  • 1356 views
  • 7 likes
  • 4 in conversation