<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: VS Code SAS: How do I set up relative references? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958807#M43068</link>
    <description>&lt;P&gt;In a SAS session for VS Code, the value of the _SASFILEPATH macro variable is automatically set when you run code from a saved program file.&amp;nbsp;You can extract the path portion of a fully qualified Windows file name like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filepath=%qsubstr(%superq(_SASPROGRAMFILE),1,%sysevalf(&lt;FONT color="#3366FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;-1));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This part of the code reads backward from the end of the string, and finds the location of the first '\' character:&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;The next portion takes that value and subtracts 1:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&lt;FONT color="#993300"&gt;%sysevalf(&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#0000FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#993300"&gt;-1)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Now we know the location of the end of the path in the text, so we use %QSUBSTR to extract the text from position 1 to the calculated end position:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%qsubstr(%superq(_SASPROGRAMFILE),1,&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#993300"&gt;%sysevalf(&lt;/FONT&gt;&lt;FONT color="#0000FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;&lt;FONT color="#993300"&gt;-1)&lt;/FONT&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;We can execute a %PUT statement to see the value in the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put NOTE: Path is %superq(filepath);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which yields:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;NOTE: Path is c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Feb 2025 13:29:54 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2025-02-10T13:29:54Z</dc:date>
    <item>
      <title>VS Code SAS: How do I set up relative references?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958475#M43036</link>
      <description>&lt;P&gt;I would like my code to be able to run out of the box when downloaded from my GitHub portfolio (this is just the standard for the other 2 coding languages on it). However, while normal SAS files will let me set the current working directory by clicking the SAS file,&amp;nbsp; this is not the case with the sasnb files on VS Code. As such, sasnb files can not run out of the box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;System notes: Windows 11, SAS on VS Code was last updated 2025-02-05.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Observation:&lt;/P&gt;&lt;P&gt;SAS will run this whenever I run code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let _SASPROGRAMFILE = %nrquote(%nrstr(c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01\01.sasnb));&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attempted solution: I can use the above as &amp;amp;_SASPROGRAMFILE. I have tried to extract c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01 so that I can send this to a rc=dlgcdir step, but I haven't managed to figure it out. I have found that the regex code ^(.+)\\ will highlight that, and its output will suffice for the rc=dlgcdir step. The issue is regexing the &amp;amp;_SASPROGRAMFILE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is just one attempted solution. Is there a simpler way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 23:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958475#M43036</guid>
      <dc:creator>KeanuHua4</dc:creator>
      <dc:date>2025-02-05T23:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: VS Code SAS: How do I set up relative references?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958807#M43068</link>
      <description>&lt;P&gt;In a SAS session for VS Code, the value of the _SASFILEPATH macro variable is automatically set when you run code from a saved program file.&amp;nbsp;You can extract the path portion of a fully qualified Windows file name like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filepath=%qsubstr(%superq(_SASPROGRAMFILE),1,%sysevalf(&lt;FONT color="#3366FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;-1));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This part of the code reads backward from the end of the string, and finds the location of the first '\' character:&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;The next portion takes that value and subtracts 1:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&lt;FONT color="#993300"&gt;%sysevalf(&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#0000FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#993300"&gt;-1)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Now we know the location of the end of the path in the text, so we use %QSUBSTR to extract the text from position 1 to the calculated end position:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%qsubstr(%superq(_SASPROGRAMFILE),1,&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#993300"&gt;%sysevalf(&lt;/FONT&gt;&lt;FONT color="#0000FF"&gt;%sysfunc(find(%superq(_SASPROGRAMFILE),\,-99999))&lt;/FONT&gt;&lt;FONT color="#993300"&gt;-1)&lt;/FONT&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;We can execute a %PUT statement to see the value in the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put NOTE: Path is %superq(filepath);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which yields:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;NOTE: Path is c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 13:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958807#M43068</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2025-02-10T13:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: VS Code SAS: How do I set up relative references?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958824#M43070</link>
      <description>&lt;P&gt;Can you explain in more detail what you are doing?&lt;/P&gt;
&lt;P&gt;Are you asking how to remove the filename part from a full qualified filename so that you just have the directory name?&amp;nbsp; You should be able to use FINDC() and SUBSTRN() easily enough.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _SASPROGRAMFILE = %nrquote(%nrstr(c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01\01.sasnb));

data _null_;
  length dirname $256;
  loc = findc(symget('_SASPROGRAMFILE'),'/\',-9999);
  dirname=substrn(symget('_SASPROGRAMFILE'),1,loc);
  put dirname=:$quote.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So once you have the directory name you could pass it to DLGCDIR() to change current directory.&lt;/P&gt;
&lt;P&gt;Assuming that the directory actually exists on the machine where SAS itself is running.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;107  %let _SASPROGRAMFILE = %nrquote(%nrstr(c:\Users\3sekk\Desktop\spring
107! 25\stat 574\hw1STAT574S25\01\01.sasnb));
108
109  data _null_;
110    length dirname $256;
111    loc = findc(symget('_SASPROGRAMFILE'),'/\',-9999);
112    dirname=substrn(symget('_SASPROGRAMFILE'),1,loc);
113    if fileexist(dirname) then rc=dlgcdir(dirname);
114    else put 'NOTE: ' dirname= 'does not exist.';
115  run;

NOTE: dirname=c:\Users\3sekk\Desktop\spring 25\stat 574\hw1STAT574S25\01\
does not exist.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is the SAS session you are using VSCODE to submit SAS code to running on the same machine as the machine that is running VSCODE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 17:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/VS-Code-SAS-How-do-I-set-up-relative-references/m-p/958824#M43070</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-10T17:24:57Z</dc:date>
    </item>
  </channel>
</rss>

